using Boo.Lang.Runtime;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityScript.Lang;

[Serializable]
public class terraincomposer_save : MonoBehaviour
{
	public int colormap_resolution;

	public GameObject Combine_Children;

	public string software_version;

	public float software_id;

	public string filename;

	public Texture2D tex1;

	public int create_pass;

	public string[] heightmap_resolution_list;

	public string[] splatmap_resolution_list;

	public string[] detailmap_resolution_list;

	public string[] detail_resolution_per_patch_list;

	public string[] image_import_max_settings;

	public TreeInstance[] trees;

	public int tree_number;

	public List<subfilter_class> subfilter;

	public List<filter_class> filter;

	public List<precolor_range_class> precolor_range;

	[NonSerialized]
	public terraincomposer_save script;

	public int show_prelayer;

	public List<prelayer_class> prelayers;

	public prelayer_class prelayer;

	public List<int> prelayer_stack;

	public List<Rect> area_stack;

	public bool area_stack_enabled;

	public bool area_skip;

	public List<GenerateArea_Class> areaStack;

	public int count_area;

	public bool layer_count;

	public bool placed_count;

	public bool overlap;

	public int layer_heightmap;

	public int layer_color;

	public int layer_splat;

	public int layer_tree;

	public int layer_grass;

	public int layer_object;

	public bool layer_heightmap_foldout;

	public bool layer_color_foldout;

	public bool layer_splat_foldout;

	public bool layer_tree_foldout;

	public bool layer_grass_foldout;

	public bool layer_object_foldout;

	public layer_class current_layer;

	public filter_class current_filter;

	public subfilter_class current_subfilter;

	public string terrain_text;

	public terrain_class masterTerrain;

	public List<terrain_class> terrains;

	public string raw_path;

	public string raw_save_path;

	public bool terrains_foldout;

	public bool terrainSearch;

	public Transform terrainSearchParent;

	public Rect terrainMenuRect;

	public bool terrains_active;

	public bool terrains_foldout2;

	public remarks_class remarks;

	public remarks_class mesh_remarks;

	public int terrain_instances;

	public Vector2 terrainInstances;

	public bool terrain_asset_erase;

	public int terrain_tiles;

	public Vector2 terrainTiles;

	public bool terrainTileLink;

	public string terrain_path;

	public Transform terrain_parent;

	public string terrain_scene_name;

	public string terrain_asset_name;

	public float object_resolution;

	public Transform object_search;

	public List<mesh_class> meshes;

	public int meshes_layer;

	public bool meshes_active;

	public bool meshes_foldout;

	public bool meshes_foldout2;

	public float meshes_heightscale;

	public area_class meshes_area;

	public string mesh_text;

	public mesh_measure_class mesh_measure;

	public string terrain_slice_path;

	public Transform terrain_slice_parent;

	public bool swap_color_range_select;

	public int swap_color_range_number;

	public precolor_range_class swap_precolor_range;

	public bool copy_color_range_select;

	public bool swap_tree_select;

	public tree_class swap_tree1;

	public tree_output_class swap_tree_output;

	public int swap_tree_position;

	public bool copy_tree_select;

	public tree_class copy_tree1;

	public bool swap_object_select;

	public object_output_class swap_object_output;

	public int swap_object_number;

	public bool copy_object_select;

	public bool swap_description_select;

	public int swap_description_prelayer_index;

	public int swap_description_position;

	public bool copy_description_select;

	public int copy_description_prelayer_index;

	public int copy_description_position;

	public bool swap_layer_select;

	public int swap_prelayer_index;

	public int swap_layer_index;

	public bool copy_layer_select;

	public int copy_prelayer_index;

	public int copy_layer_index;

	public bool swap_filter_select;

	public bool copy_filter_select;

	public bool swap_subfilter_select;

	public presubfilter_class swap_presubfilter;

	public int swap_subfilter_index;

	public bool copy_subfilter_select;

	public subfilter_class copy_subfilter1;

	public terrain_class preterrain;

	public mesh_class premesh;

	public float mix;

	public float xx;

	public float zz;

	public float resolution;

	public int splat_plus;

	public float Rad2Deg;

	public detail_class[] grass_detail;

	public SplatPrototype splat1;

	public int count_value;

	public int count_color_range;

	public int count_prelayer;

	public int count_layer;

	public int count_tree;

	public int count_object;

	public int count_filter;

	public int count_subfilter;

	public int call_from;

	public float random_range;

	public float random_range2;

	public Color color1;

	public Color color2;

	public float color_r;

	public float color_g;

	public float color_b;

	public float color_a;

	public bool heightmap_output;

	public bool heightmap_output_layer;

	public bool color_output;

	public bool splat_output;

	public bool tree_output;

	public bool grass_output;

	public bool object_output;

	public bool world_output;

	public bool line_output;

	public bool button1;

	public bool button_export;

	public string button_generate_text;

	public Texture2D export_texture;

	public byte[] export_bytes;

	public string export_file;

	public string export_path;

	public string export_name;

	public bool export_color_advanced;

	public Color export_color;

	public bool export_color_curve_advanced;

	public AnimationCurve export_color_curve;

	public AnimationCurve export_color_curve_red;

	public AnimationCurve export_color_curve_green;

	public AnimationCurve export_color_curve_blue;

	public int seed;

	public bool generate;

	public bool generateDone;

	public bool generate_manual;

	public int generate_speed;

	public bool generate_speed_display;

	public bool generate_sub_break;

	public bool generate_pause;

	public float generate_call_time;

	public float generate_call_time2;

	public float generate_call_delay;

	public float generate_time;

	public float generate_time_start;

	public bool generate_on_top;

	public bool generate_world_mode;

	public bool generate_auto;

	public int generate_auto_mode;

	public float generate_auto_delay1;

	public float generate_auto_delay2;

	public bool generate_call;

	public bool generate_error;

	public int generate_export;

	public float[,] heights;

	public float[,,] alphamap;

	public List<TreeInstance> tree_instances;

	public int grass_resolution_old;

	public Color color;

	public int object_speed;

	public bool runtime;

	public bool auto_speed;

	public float auto_speed_time;

	public float auto_speed_object_time;

	public int min_speed;

	public float frames;

	public float object_frames;

	public int target_frame;

	public bool only_heightmap;

	public int terrain_index_old;

	public Color tree_color;

	public float layer_x;

	public float layer_y;

	public bool unload_textures;

	public bool clean_memory;

	public float splat_total;

	public List<distance_class> objects_placed;

	public distance_class object_info;

	public int heightmap_x;

	public int heightmap_y;

	public int heightmap_x_old;

	public int heightmap_y_old;

	public int detailmap_x;

	public int detailmap_y;

	public int h_local_x;

	public int h_local_y;

	public int map_x;

	public int map_y;

	public bool measure_normal;

	public bool place;

	public Vector3 position;

	public Vector3 scale;

	public float height;

	public float height_interpolated;

	public float degree;

	public Vector3 normal;

	public float local_x_rot;

	public float local_y_rot;

	public float local_x;

	public float local_y;

	public float a;

	public float b;

	public System.Random random;

	public bool measure_tool;

	public bool measure_tool_foldout;

	public bool measure_tool_active;

	public bool measure_tool_undock;

	public bool measure_tool_clicked;

	public float measure_tool_range;

	public bool measure_tool_inrange;

	public Vector2 measure_tool_terrain_point;

	public Vector2 measure_tool_terrain_point_interpolated;

	public bool measure_tool_converter_foldout;

	public float measure_tool_converter_height_input;

	public float measure_tool_converter_height;

	public float measure_tool_converter_angle_input;

	public float measure_tool_converter_angle;

	public bool stitch_tool;

	public bool stitch_tool_foldout;

	public float stitch_tool_border_influence;

	public AnimationCurve stitch_tool_curve;

	public float stitch_tool_strength;

	public bool stitch_command;

	public bool smooth_tool;

	public bool smooth_tool_foldout;

	public float smooth_tool_strength;

	public int smooth_tool_repeat;

	public bool smooth_tool_advanced;

	public float smooth_tool_layer_strength;

	public bool smooth_command;

	public string[] smooth_tool_terrain;

	public int smooth_tool_terrain_select;

	public animation_curve_class smooth_tool_height_curve;

	public animation_curve_class smooth_tool_angle_curve;

	public bool quick_tools;

	public bool quick_tools_foldout;

	public bool slice_tool;

	public bool slice_tool_active;

	public bool slice_tool_foldout;

	public bool slice_tool_heightmap_foldout;

	public bool slice_tool_all_foldout;

	public Rect slice_tool_rect;

	public Terrain slice_tool_terrain;

	public bool slice_tool_erase_terrain_scene;

	public bool slice_tool_erase_terrain_data;

	public Vector2 slice_tool_offset;

	public float slice_tool_min_height;

	public bool sphere_draw;

	public float sphere_radius;

	public Vector3 measure_tool_point_old;

	public bool image_tools;

	public texture_tool_class texture_tool;

	public pattern_tool_class pattern_tool;

	public heightmap_tool_class heightmap_tool;

	public bool description_display;

	public float description_space;

	public animation_curve_class curve_in_memory_old;

	public bool meshcapture_tool;

	public bool meshcapture_tool_foldout;

	public GameObject meshcapture_tool_object;

	public Texture2D meshcapture_tool_image;

	public Transform meshcapture_tool_pivot;

	public int meshcapture_tool_image_width;

	public int meshcapture_tool_image_height;

	public float meshcapture_tool_scale;

	public bool meshcapture_tool_save_scale;

	public bool meshcapture_tool_shadows;

	public Color meshcapture_tool_color;

	public Color meshcapture_background_color;

	public int row_object_count;

	public bool break_x;

	public float break_time;

	public float break_time_set;

	public bool generate_settings;

	public bool generate_settings_foldout;

	public int tile_resolution;

	public int trees_maximum;

	public terraincomposer_save script_base;

	public save_trees tree_script;

	public save_grass grass_script;

	public int tc_id;

	public settings_class settings;

	public RaycastHit hit;

	public int layerHit;

	public GameObject TerrainComposer_Parent;

	[HideInInspector]
	public float filter_value;

	[HideInInspector]
	public float filter_strength;

	[HideInInspector]
	public float filter_input;

	[HideInInspector]
	public float filter_combine;

	[HideInInspector]
	public float filter_combine_start;

	[HideInInspector]
	public float subfilter_value;

	[HideInInspector]
	public int byte_hi2;

	[HideInInspector]
	public int byte_hi;

	[HideInInspector]
	public int byte_lo;

	public List<raw_file_class> raw_files;

	public bool converted_resolutions;

	public float converted_version;

	public GameObject RTP_LODmanager1;

	public Component rtpLod_script;

	public List<object_point_class> pointsRange;

	public List<GameObject> placedObjects;

	public Vector2 imagePosition;

	public terraincomposer_save()
	{
		colormap_resolution = 2048;
		software_version = "Beta";
		create_pass = -1;
		heightmap_resolution_list = new string[8]
		{
			"4097",
			"2049",
			"1025",
			"513",
			"257",
			"129",
			"65",
			"33"
		};
		splatmap_resolution_list = new string[8]
		{
			"2048",
			"1024",
			"512",
			"256",
			"128",
			"64",
			"32",
			"16"
		};
		detailmap_resolution_list = new string[9]
		{
			"2048",
			"1024",
			"512",
			"256",
			"128",
			"64",
			"32",
			"16",
			"8"
		};
		detail_resolution_per_patch_list = new string[5]
		{
			"8",
			"16",
			"32",
			"64",
			"128"
		};
		image_import_max_settings = new string[8]
		{
			"32",
			"64",
			"128",
			"256",
			"512",
			"1024",
			"2048",
			"4096"
		};
		subfilter = new List<subfilter_class>();
		filter = new List<filter_class>();
		precolor_range = new List<precolor_range_class>();
		prelayers = new List<prelayer_class>();
		prelayer_stack = new List<int>();
		area_stack = new List<Rect>();
		areaStack = new List<GenerateArea_Class>();
		layer_count = true;
		placed_count = true;
		terrain_text = "Terrain:";
		terrains = new List<terrain_class>();
		raw_path = string.Empty;
		raw_save_path = string.Empty;
		terrains_foldout = true;
		terrains_active = true;
		terrains_foldout2 = true;
		remarks = new remarks_class();
		mesh_remarks = new remarks_class();
		terrain_instances = 1;
		terrain_tiles = 1;
		terrainTileLink = true;
		terrain_scene_name = "Terrain";
		terrain_asset_name = "New Terrain";
		object_resolution = 10f;
		meshes = new List<mesh_class>();
		meshes_active = true;
		meshes_foldout = true;
		meshes_foldout2 = true;
		meshes_area = new area_class();
		mesh_text = "Meshes";
		mesh_measure = new mesh_measure_class();
		resolution = 2048f;
		splat_plus = 1;
		Rad2Deg = 57.29578f;
		splat1 = new SplatPrototype();
		heightmap_output = true;
		color_output = true;
		splat_output = true;
		tree_output = true;
		grass_output = true;
		object_output = true;
		button_generate_text = "Generate";
		export_file = string.Empty;
		export_color_advanced = true;
		export_color = Color.white;
		export_color_curve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
		export_color_curve_red = AnimationCurve.Linear(0f, 0f, 1f, 1f);
		export_color_curve_green = AnimationCurve.Linear(0f, 0f, 1f, 1f);
		export_color_curve_blue = AnimationCurve.Linear(0f, 0f, 1f, 1f);
		seed = 10;
		generate_speed = 10;
		generate_on_top = true;
		generate_auto_mode = 1;
		generate_auto_delay2 = 0.2f;
		tree_instances = new List<TreeInstance>();
		object_speed = 3;
		min_speed = 3;
		target_frame = 60;
		terrain_index_old = -1;
		unload_textures = true;
		clean_memory = true;
		objects_placed = new List<distance_class>();
		object_info = new distance_class();
		place = true;
		random = new System.Random();
		measure_tool_foldout = true;
		measure_tool_range = 10000f;
		stitch_tool = true;
		stitch_tool_foldout = true;
		stitch_tool_border_influence = 20f;
		stitch_tool_curve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
		stitch_tool_strength = 1f;
		smooth_tool = true;
		smooth_tool_foldout = true;
		smooth_tool_strength = 1f;
		smooth_tool_repeat = 1;
		smooth_tool_layer_strength = 1f;
		smooth_tool_height_curve = new animation_curve_class();
		smooth_tool_angle_curve = new animation_curve_class();
		quick_tools = true;
		slice_tool = true;
		slice_tool_foldout = true;
		slice_tool_erase_terrain_scene = true;
		slice_tool_offset = default(Vector2);
		sphere_draw = true;
		sphere_radius = 10f;
		texture_tool = new texture_tool_class();
		pattern_tool = new pattern_tool_class();
		heightmap_tool = new heightmap_tool_class();
		description_display = true;
		description_space = 15f;
		meshcapture_tool = true;
		meshcapture_tool_foldout = true;
		meshcapture_tool_image_width = 128;
		meshcapture_tool_image_height = 128;
		meshcapture_tool_scale = 1f;
		meshcapture_tool_save_scale = true;
		meshcapture_tool_color = Color.white;
		meshcapture_background_color = Color.black;
		break_time = 0.2f;
		generate_settings_foldout = true;
		tile_resolution = 1000;
		trees_maximum = 1000;
		settings = new settings_class();
		raw_files = new List<raw_file_class>();
		pointsRange = new List<object_point_class>();
		placedObjects = new List<GameObject>();
	}

	public heightmap_type_enum GetHeightmapEnum(condition_type_enum input)
	{
		int result;
		switch (input)
		{
		case condition_type_enum.Image:
			result = 0;
			break;
		case condition_type_enum.Random:
			result = 1;
			break;
		case condition_type_enum.RandomRange:
			result = 2;
			break;
		case condition_type_enum.Current:
			result = 4;
			break;
		case condition_type_enum.RawHeightmap:
			result = 5;
			break;
		case condition_type_enum.RayCast:
			result = 6;
			break;
		default:
			result = 3;
			break;
		}
		return (heightmap_type_enum)result;
	}

	public condition_type_enum GetCondtionTypeEnum(heightmap_type_enum input)
	{
		int result;
		switch (input)
		{
		case heightmap_type_enum.Image:
			result = 3;
			break;
		case heightmap_type_enum.Random:
			result = 4;
			break;
		case heightmap_type_enum.RandomRange:
			result = 5;
			break;
		case heightmap_type_enum.Current:
			result = 7;
			break;
		case heightmap_type_enum.RawHeightmap:
			result = 9;
			break;
		case heightmap_type_enum.RayCast:
			result = 11;
			break;
		default:
			result = 6;
			break;
		}
		return (condition_type_enum)result;
	}

	public void add_prelayer(bool search_level)
	{
		prelayers.Add(new prelayer_class(0, prelayers.Count));
		prelayers[prelayers.Count - 1].index = prelayers.Count - 1;
		prelayers[prelayers.Count - 1].prearea.area_max = settings.area_max;
		prelayers[prelayers.Count - 1].prearea.max();
		prelayers[prelayers.Count - 1].set_prelayer_text();
		if (search_level)
		{
			search_level_prelayer(0, prelayers.Count - 1, 0);
		}
	}

	public void erase_prelayer(int prelayer_index)
	{
		erase_layers(prelayers[prelayer_index]);
		if (prelayer_index < prelayers.Count - 1)
		{
			swap_prelayer1(prelayer_index, prelayers.Count - 1);
		}
		prelayers.RemoveAt(prelayers.Count - 1);
		if (prelayer_index < prelayers.Count)
		{
			search_prelayer(prelayer_index);
			prelayers[prelayer_index].index = prelayer_index;
			prelayers[prelayer_index].set_prelayer_text();
		}
	}

	public void search_prelayer(int prelayer_index)
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				for (int k = 0; k < prelayers[i].layer[j].object_output.@object.Count; k++)
				{
					if (prelayers[i].layer[j].object_output.@object[k].prelayer_index == prelayers.Count)
					{
						prelayers[i].layer[j].object_output.@object[k].prelayer_index = prelayer_index;
						return;
					}
				}
			}
		}
	}

	public void search_level_prelayer(int prelayer_index, int find_index, int level)
	{
		for (int i = 0; i < prelayers[prelayer_index].layer.Count; i++)
		{
			for (int j = 0; j < prelayers[prelayer_index].layer[i].object_output.@object.Count; j++)
			{
				if (prelayers[prelayer_index].layer[i].object_output.@object[j].prelayer_created)
				{
					level++;
					if (prelayers[prelayer_index].layer[i].object_output.@object[j].prelayer_index == find_index)
					{
						prelayers[prelayers[prelayer_index].layer[i].object_output.@object[j].prelayer_index].level = level;
						return;
					}
					search_level_prelayer(prelayers[prelayer_index].layer[i].object_output.@object[j].prelayer_index, find_index, level);
					level--;
				}
			}
		}
	}

	public void swap_prelayer1(int prelayer_index1, int prelayer_index2)
	{
		prelayer_class prelayer_class = prelayers[prelayer_index1];
		prelayers[prelayer_index1] = prelayers[prelayer_index2];
		prelayers[prelayer_index2] = prelayers[prelayer_index1];
	}

	public void new_layergroup(prelayer_class prelayer1, int description_number)
	{
		int count = prelayer1.predescription.description[description_number].layer_index.Count;
		for (int i = 0; i < count; i++)
		{
			erase_layer(prelayer1, prelayer1.predescription.description[description_number].layer_index[0], description_number, 0, description: true, loop_layer: true, count_layer: false);
		}
	}

	public void erase_description(prelayer_class prelayer1, int description_number)
	{
		if (prelayer1.predescription.description.Count > 1)
		{
			int count = prelayer1.predescription.description[description_number].layer_index.Count;
			for (int i = 0; i < count; i++)
			{
				erase_layer(prelayer1, prelayer1.predescription.description[description_number].layer_index[0], description_number, 0, description: true, loop_layer: true, count_layer: false);
			}
			prelayer1.predescription.erase_description(description_number);
		}
		count_layers();
	}

	public void swap_description(int description_number1, int description_number2, prelayer_class prelayer1)
	{
		if (description_number2 >= 0 && description_number2 <= prelayer1.predescription.description.Count - 1)
		{
			int count = prelayer1.predescription.description[description_number1].layer_index.Count;
			int count2 = prelayer1.predescription.description[description_number2].layer_index.Count;
			int num = default(int);
			string text = prelayer1.predescription.description[description_number1].text;
			bool edit = prelayer1.predescription.description[description_number1].edit;
			prelayer1.predescription.description[description_number1].text = prelayer1.predescription.description[description_number2].text;
			prelayer1.predescription.description[description_number2].text = text;
			prelayer1.predescription.description[description_number1].edit = prelayer1.predescription.description[description_number2].edit;
			prelayer1.predescription.description[description_number2].edit = edit;
			bool foldout = prelayer1.predescription.description[description_number1].foldout;
			prelayer1.predescription.description[description_number1].foldout = prelayer1.predescription.description[description_number2].foldout;
			prelayer1.predescription.description[description_number2].foldout = foldout;
			for (num = 0; num < count; num++)
			{
				replace_layer(0, description_number1, description_number2, prelayer1);
			}
			for (num = 0; num < count2; num++)
			{
				replace_layer(0, description_number2, description_number1, prelayer1);
			}
			prelayer1.predescription.set_description_enum();
		}
	}

	public void replace_layer(int source_layer_index, int source_description_number, int target_description_number, prelayer_class prelayer1)
	{
		int num = get_layer_position(prelayer1.predescription.description[target_description_number].layer_index.Count, target_description_number, prelayer1);
		add_layer(prelayer1, num, layer_output_enum.color, target_description_number, prelayer1.predescription.description[target_description_number].layer_index.Count, new_filter: false, count_layer: false, custom: true);
		prelayer1.layer[num] = copy_layer(prelayer1.layer[prelayer1.predescription.description[source_description_number].layer_index[source_layer_index]], copy_filter: true, loop: true);
		erase_layer(prelayer1, prelayer1.predescription.description[source_description_number].layer_index[source_layer_index], source_description_number, source_layer_index, description: true, loop_layer: true, count_layer: true);
	}

	public void count_layers()
	{
		if (!layer_count)
		{
			return;
		}
		layer_heightmap = (layer_color = (layer_splat = (layer_tree = (layer_grass = (layer_object = 0)))));
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				switch (prelayers[i].layer[j].output)
				{
				case layer_output_enum.heightmap:
					layer_heightmap++;
					break;
				case layer_output_enum.color:
					layer_color++;
					break;
				case layer_output_enum.splat:
					layer_splat++;
					break;
				case layer_output_enum.tree:
					layer_tree++;
					break;
				case layer_output_enum.grass:
					layer_grass++;
					break;
				case layer_output_enum.@object:
					layer_object++;
					break;
				}
			}
		}
	}

	public void erase_layers(prelayer_class prelayer1)
	{
		int count = prelayer1.layer.Count;
		for (int i = 0; i < count; i++)
		{
			erase_layer(prelayer1, 0, 0, 0, description: false, loop_layer: true, count_layer: false);
		}
	}

	public void erase_layer(prelayer_class prelayer1, int layer_number, int description_number, int layer_index, bool description, bool loop_layer, bool count_layer)
	{
		if (prelayer1.layer.Count > 0)
		{
			if (loop_layer)
			{
				this.loop_layer(prelayer1.layer[layer_number], -1);
			}
			erase_filters(prelayer1.layer[layer_number].prefilter);
			for (int i = 0; i < prelayer1.layer[layer_number].tree_output.tree.Count; i++)
			{
				erase_filters(prelayer1.layer[layer_number].tree_output.tree[i].prefilter);
			}
			prelayer1.layer.RemoveAt(layer_number);
		}
		if (description)
		{
			prelayer1.predescription.erase_layer_index(layer_number, layer_index, description_number);
		}
		if (count_layer)
		{
			count_layers();
		}
		prelayer1.set_prelayer_text();
	}

	public void strip_layer(prelayer_class prelayer1, int layer_number)
	{
		for (int i = 0; i < prelayer1.layer[layer_number].object_output.@object.Count; i++)
		{
			if (prelayer1.layer[layer_number].object_output.@object[i].prelayer_created)
			{
				erase_prelayer(prelayer1.layer[layer_number].object_output.@object[i].prelayer_index);
			}
		}
		erase_filters(prelayer1.layer[layer_number].prefilter);
	}

	public void add_layer(prelayer_class prelayer1, int layer_number, layer_output_enum layer_output, int description_number, int layer_index, bool new_filter, bool count_layer, bool custom)
	{
		prelayer1.layer.Insert(layer_number, new layer_class());
		if (new_filter)
		{
			add_filter(0, prelayer1.layer[layer_number].prefilter);
		}
		prelayer1.layer[layer_number].output = layer_output;
		prelayer1.predescription.add_layer_index(layer_number, layer_index, description_number);
		if (count_layer)
		{
			count_layers();
		}
		prelayer1.set_prelayer_text();
		if (layer_output == layer_output_enum.heightmap && custom && new_filter)
		{
			filter[filter.Count - 1].type = condition_type_enum.Always;
		}
	}

	public void swap_layer(prelayer_class prelayer1, int layer_number1, prelayer_class prelayer2, int layer_number2, bool blink)
	{
		if (layer_number2 < 0 || layer_number2 > prelayer2.layer.Count - 1)
		{
			return;
		}
		layer_class value = prelayer1.layer[layer_number1];
		prelayer1.layer[layer_number1] = prelayer2.layer[layer_number2];
		prelayer2.layer[layer_number2] = value;
		if (blink)
		{
			if (!(prelayer1.layer[layer_number1].color_layer[0] >= 1.5f))
			{
				prelayer1.layer[layer_number1].color_layer = prelayer1.layer[layer_number1].color_layer + new Color(1f, 1f, 1f, 1f);
			}
			if (!(prelayer2.layer[layer_number2].color_layer[0] >= 1.5f))
			{
				prelayer2.layer[layer_number2].color_layer = prelayer2.layer[layer_number2].color_layer + new Color(1f, 1f, 1f, 1f);
			}
		}
	}

	public int get_layer_position(int layer_index, int description_number, prelayer_class prelayer1)
	{
		int num = 0;
		int num2 = 0;
		int result;
		while (true)
		{
			if (num2 < prelayer1.predescription.description.Count)
			{
				if (num2 == description_number)
				{
					result = num + layer_index;
					break;
				}
				num += prelayer1.predescription.description[num2].layer_index.Count;
				num2++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public int get_layer_description(prelayer_class prelayer1, int layer_index)
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < prelayer1.predescription.description.Count)
			{
				int num2 = 0;
				while (num2 < prelayer1.predescription.description[num].layer_index.Count)
				{
					if (prelayer1.predescription.description[num].layer_index[num2] != layer_index)
					{
						num2++;
						continue;
					}
					goto IL_0030;
				}
				num++;
				continue;
			}
			result = -1;
			break;
			IL_0030:
			result = num;
			break;
		}
		return result;
	}

	public void layer_sort(prelayer_class prelayer, int description_number)
	{
		int num = default(int);
		bool flag = false;
		bool flag2 = false;
		bool flag3 = false;
		bool flag4 = false;
		bool flag5 = false;
		bool flag6 = false;
		int index = default(int);
		int index2 = default(int);
		int index3 = default(int);
		int index4 = default(int);
		int index5 = default(int);
		int index6 = default(int);
		for (int i = 0; i < prelayer.predescription.description[description_number].layer_index.Count; i++)
		{
			flag = false;
			flag2 = false;
			flag3 = false;
			flag4 = false;
			flag5 = false;
			flag6 = false;
			for (int j = i; j < prelayer.predescription.description[description_number].layer_index.Count; j++)
			{
				if (!flag && prelayer.layer[prelayer.predescription.description[description_number].layer_index[j]].output == layer_output_enum.heightmap)
				{
					index = j;
					flag = true;
				}
				if (!flag2 && prelayer.layer[prelayer.predescription.description[description_number].layer_index[j]].output == layer_output_enum.color)
				{
					index2 = j;
					flag2 = true;
				}
				if (!flag3 && prelayer.layer[prelayer.predescription.description[description_number].layer_index[j]].output == layer_output_enum.splat)
				{
					index3 = j;
					flag3 = true;
				}
				if (!flag4 && prelayer.layer[prelayer.predescription.description[description_number].layer_index[j]].output == layer_output_enum.tree)
				{
					index4 = j;
					flag4 = true;
				}
				if (!flag5 && prelayer.layer[prelayer.predescription.description[description_number].layer_index[j]].output == layer_output_enum.grass)
				{
					index5 = j;
					flag5 = true;
				}
				if (!flag6 && prelayer.layer[prelayer.predescription.description[description_number].layer_index[j]].output == layer_output_enum.@object)
				{
					index6 = j;
					flag6 = true;
				}
			}
			if (flag)
			{
				swap_layer(prelayer, prelayer.predescription.description[description_number].layer_index[i], prelayer, prelayer.predescription.description[description_number].layer_index[index], blink: false);
			}
			else if (flag2)
			{
				swap_layer(prelayer, prelayer.predescription.description[description_number].layer_index[i], prelayer, prelayer.predescription.description[description_number].layer_index[index2], blink: false);
			}
			else if (flag3)
			{
				swap_layer(prelayer, prelayer.predescription.description[description_number].layer_index[i], prelayer, prelayer.predescription.description[description_number].layer_index[index3], blink: false);
			}
			else if (flag4)
			{
				swap_layer(prelayer, prelayer.predescription.description[description_number].layer_index[i], prelayer, prelayer.predescription.description[description_number].layer_index[index4], blink: false);
			}
			else if (flag5)
			{
				swap_layer(prelayer, prelayer.predescription.description[description_number].layer_index[i], prelayer, prelayer.predescription.description[description_number].layer_index[index5], blink: false);
			}
			else if (flag6)
			{
				swap_layer(prelayer, prelayer.predescription.description[description_number].layer_index[i], prelayer, prelayer.predescription.description[description_number].layer_index[index6], blink: false);
			}
		}
	}

	public void LayerSort(prelayer_class prelayer, int layerGroupIndex)
	{
		description_class description_class = prelayer.predescription.description[layerGroupIndex];
		layer_class layer_class = null;
		layer_class layer_class2 = null;
		int num = -1;
		int num2 = default(int);
		int num3 = default(int);
		for (int i = 1; i < description_class.layer_index.Count; i++)
		{
			layer_class = prelayer.layer[description_class.layer_index[i]];
			layer_class2 = prelayer.layer[description_class.layer_index[i - 1]];
			num2 = (int)layer_class.output;
			num3 = (int)layer_class2.output;
			if (num2 < num3)
			{
				swap_layer(prelayer, prelayer.predescription.description[layerGroupIndex].layer_index[i], prelayer, prelayer.predescription.description[layerGroupIndex].layer_index[i - 1], blink: false);
				if (num == -1)
				{
					num = i;
				}
				if (i > 1)
				{
					i -= 2;
					continue;
				}
				i = num;
				num = -1;
			}
			else if (num != -1)
			{
				i = num;
				num = -1;
			}
		}
	}

	public void layers_sort(prelayer_class prelayer)
	{
		for (int i = 0; i < prelayer.predescription.description.Count; i++)
		{
			LayerSort(prelayer, i);
		}
	}

	public void erase_filters(prefilter_class prefilter)
	{
		int count = prefilter.filter_index.Count;
		for (int i = 0; i < count; i++)
		{
			erase_filter(0, prefilter);
		}
	}

	public void add_filter(int filter_number, prefilter_class prefilter)
	{
		filter.Add(new filter_class());
		prefilter.filter_index.Insert(filter_number, filter.Count - 1);
		if (terrains.Count > 1)
		{
			filter[filter.Count - 1].preimage.image_mode = image_mode_enum.MultiTerrain;
		}
		prefilter.set_filter_text();
	}

	public void add_animation_curve(List<animation_curve_class> precurve_list, int curve_number, bool copy)
	{
		if (!copy)
		{
			precurve_list.Insert(curve_number, new animation_curve_class());
			precurve_list[curve_number].curve = AnimationCurve.Linear(0f, 0f, 1f, 0f);
			precurve_list[curve_number].default_curve = new AnimationCurve(precurve_list[curve_number].curve.keys);
		}
		else
		{
			precurve_list.Insert(curve_number, copy_animation_curve(precurve_list[curve_number - 1]));
		}
	}

	public void erase_animation_curve(List<animation_curve_class> precurve_list, int curve_number)
	{
		if (precurve_list.Count > 0)
		{
			precurve_list.RemoveAt(curve_number);
		}
	}

	public void swap_animation_curve(List<animation_curve_class> curve_list, int curve_number1, int curve_number2)
	{
		animation_curve_class value = curve_list[curve_number1];
		curve_list[curve_number1] = curve_list[curve_number2];
		curve_list[curve_number2] = value;
	}

	public void erase_filter(int filter_number, prefilter_class prefilter)
	{
		if (prefilter.filter_index.Count > 0)
		{
			erase_subfilters(filter[prefilter.filter_index[filter_number]]);
			int num = prefilter.filter_index[filter_number];
			swap_filter2(num, filter.Count - 1, blink: false);
			filter.RemoveAt(filter.Count - 1);
			prefilter.filter_index.RemoveAt(filter_number);
			relink_filter_index(num);
			prefilter.set_filter_text();
		}
	}

	public void erase_filter_reference(prefilter_class prefilter, int filter_index)
	{
		prefilter.filter_index.RemoveAt(filter_index);
		prefilter.set_filter_text();
	}

	public void erase_filter_unlinked(int filter_number)
	{
		swap_filter2(filter_number, filter.Count - 1, blink: false);
		filter.RemoveAt(filter.Count - 1);
		relink_filter_index(filter_number);
	}

	public void swap_filter(prefilter_class prefilter1, int filter_index1, prefilter_class prefilter2, int filter_index2)
	{
		if (filter_index2 >= 0 && filter_index2 <= prefilter2.filter_index.Count - 1)
		{
			filter_class value = filter[prefilter1.filter_index[filter_index1]];
			filter[prefilter1.filter_index[filter_index1]] = filter[prefilter2.filter_index[filter_index2]];
			filter[prefilter2.filter_index[filter_index2]] = value;
			if (!(filter[prefilter1.filter_index[filter_index1]].color_filter[0] >= 1.5f))
			{
				filter[prefilter1.filter_index[filter_index1]].color_filter = filter[prefilter1.filter_index[filter_index1]].color_filter + new Color(1f, 1f, 1f, 1f);
			}
			if (!(filter[prefilter2.filter_index[filter_index2]].color_filter[0] >= 1.5f))
			{
				filter[prefilter2.filter_index[filter_index2]].color_filter = filter[prefilter2.filter_index[filter_index2]].color_filter + new Color(1f, 1f, 1f, 1f);
			}
		}
	}

	public void swap_filter2(int filter_number1, int filter_number2, bool blink)
	{
		filter_class value = filter[filter_number1];
		filter[filter_number1] = filter[filter_number2];
		filter[filter_number2] = value;
		if (blink)
		{
			if (!(filter[filter_number1].color_filter[0] >= 1.5f))
			{
				filter[filter_number1].color_filter = filter[filter_number1].color_filter + new Color(1f, 1f, 1f, 1f);
			}
			if (!(filter[filter_number2].color_filter[0] >= 1.5f))
			{
				filter[filter_number2].color_filter = filter[filter_number2].color_filter + new Color(1f, 1f, 1f, 1f);
			}
		}
	}

	public void swap_object(object_output_class object_output1, int object_number1, object_output_class object_output2, int object_number2)
	{
		object_class value = object_output1.@object[object_number1];
		float value2 = object_output1.object_value.value[object_number1];
		bool value3 = object_output1.object_value.active[object_number1];
		object_output1.@object[object_number1] = object_output2.@object[object_number2];
		object_output2.@object[object_number2] = value;
		if (!(object_output1.@object[object_number1].color_object[0] <= 0.5f))
		{
			object_output1.@object[object_number1].color_object = object_output1.@object[object_number1].color_object + new Color(-0.5f, 0f, -0.5f, 0f);
		}
		if (!(object_output2.@object[object_number2].color_object[0] <= 0.5f))
		{
			object_output2.@object[object_number2].color_object = object_output2.@object[object_number2].color_object + new Color(-0.5f, 0f, -0.5f, 0f);
		}
		object_output1.object_value.value[object_number1] = object_output2.object_value.value[object_number2];
		object_output2.object_value.value[object_number2] = value2;
		object_output1.object_value.active[object_number1] = object_output2.object_value.active[object_number2];
		object_output2.object_value.active[object_number2] = value3;
		object_output1.object_value.calc_value();
		if (!RuntimeServices.EqualityOperator(object_output1, object_output2))
		{
			object_output2.object_value.calc_value();
		}
	}

	public void swap_tree(tree_output_class tree_output1, int tree_number1, tree_output_class tree_output2, int tree_number2)
	{
		tree_class value = tree_output1.tree[tree_number1];
		float value2 = tree_output1.tree_value.value[tree_number1];
		bool value3 = tree_output1.tree_value.active[tree_number1];
		tree_output1.tree[tree_number1] = tree_output2.tree[tree_number2];
		tree_output2.tree[tree_number2] = value;
		if (!(tree_output1.tree[tree_number1].color_tree[0] >= 1.5f))
		{
			tree_output1.tree[tree_number1].color_tree = tree_output1.tree[tree_number1].color_tree + new Color(0.5f, 0.5f, 0.5f, 0f);
		}
		if (!(tree_output2.tree[tree_number2].color_tree[0] >= 1.5f))
		{
			tree_output2.tree[tree_number2].color_tree = tree_output2.tree[tree_number2].color_tree + new Color(0.5f, 0.5f, 0.5f, 0f);
		}
		tree_output1.tree_value.value[tree_number1] = tree_output2.tree_value.value[tree_number2];
		tree_output2.tree_value.value[tree_number2] = value2;
		tree_output1.tree_value.active[tree_number1] = tree_output2.tree_value.active[tree_number2];
		tree_output2.tree_value.active[tree_number2] = value3;
		tree_output1.tree_value.calc_value();
		if (!RuntimeServices.EqualityOperator(tree_output1, tree_output2))
		{
			tree_output2.tree_value.calc_value();
		}
	}

	public void add_object(object_output_class object_output, int object_number)
	{
		object_output.@object.Insert(object_number, new object_class());
		object_output.object_value.add_value(object_number, 50f);
		object_output.set_object_text();
	}

	public void erase_object(object_output_class object_output, int object_number)
	{
		if (object_output.@object.Count > 0)
		{
			if (object_output.@object[object_number].prelayer_created)
			{
				erase_prelayer(object_output.@object[object_number].prelayer_index);
			}
			object_output.@object.RemoveAt(object_number);
			object_output.object_value.erase_value(object_number);
			object_output.set_object_text();
		}
	}

	public void clear_object(object_output_class object_output)
	{
		int count = object_output.@object.Count;
		for (int i = 0; i < count; i++)
		{
			erase_object(object_output, object_output.@object.Count - 1);
		}
	}

	public void swap_color_range(precolor_range_class precolor_range1, int color_range_number1, precolor_range_class precolor_range2, int color_range_number2)
	{
		color_range_class value = precolor_range1.color_range[color_range_number1];
		float value2 = precolor_range1.color_range_value.value[color_range_number1];
		bool value3 = precolor_range1.color_range_value.active[color_range_number1];
		precolor_range1.color_range[color_range_number1] = precolor_range2.color_range[color_range_number2];
		precolor_range2.color_range[color_range_number2] = value;
		if (!(precolor_range1.color_range[color_range_number1].color_color_range[0] >= 1.5f))
		{
			precolor_range1.color_range[color_range_number1].color_color_range = precolor_range1.color_range[color_range_number1].color_color_range + new Color(1f, 1f, 1f, 1f);
		}
		if (!(precolor_range2.color_range[color_range_number2].color_color_range[0] >= 1.5f))
		{
			precolor_range2.color_range[color_range_number2].color_color_range = precolor_range2.color_range[color_range_number2].color_color_range + new Color(1f, 1f, 1f, 1f);
		}
		precolor_range1.color_range_value.value[color_range_number1] = precolor_range2.color_range_value.value[color_range_number2];
		precolor_range2.color_range_value.value[color_range_number2] = value2;
		precolor_range1.color_range_value.active[color_range_number1] = precolor_range2.color_range_value.active[color_range_number2];
		precolor_range2.color_range_value.active[color_range_number2] = value3;
		precolor_range1.color_range_value.calc_value();
		precolor_range1.set_precolor_range_curve();
		if (!RuntimeServices.EqualityOperator(precolor_range1, precolor_range2))
		{
			precolor_range2.color_range_value.calc_value();
			precolor_range2.set_precolor_range_curve();
		}
		if (precolor_range1.one_color)
		{
			precolor_range1.color_range[color_range_number1].one_color = true;
		}
		if (precolor_range2.one_color)
		{
			precolor_range2.color_range[color_range_number2].one_color = true;
		}
	}

	public void change_filters_active(prefilter_class prefilter, bool invert)
	{
		for (int i = 0; i < prefilter.filter_index.Count; i++)
		{
			if (!invert)
			{
				filter[prefilter.filter_index[i]].active = prefilter.filters_active;
			}
			else
			{
				filter[prefilter.filter_index[i]].active = !filter[prefilter.filter_index[i]].active;
			}
		}
	}

	public void change_filters_foldout(prefilter_class prefilter, bool invert)
	{
		for (int i = 0; i < prefilter.filter_index.Count; i++)
		{
			if (!invert)
			{
				filter[prefilter.filter_index[i]].foldout = prefilter.filters_foldout;
			}
			else
			{
				filter[prefilter.filter_index[i]].foldout = !filter[prefilter.filter_index[i]].foldout;
			}
		}
	}

	public void change_subfilters_active(presubfilter_class presubfilter, bool invert)
	{
		for (int i = 0; i < presubfilter.subfilter_index.Count; i++)
		{
			if (!invert)
			{
				subfilter[presubfilter.subfilter_index[i]].active = presubfilter.subfilters_active;
			}
			else
			{
				subfilter[presubfilter.subfilter_index[i]].active = !subfilter[presubfilter.subfilter_index[i]].active;
			}
		}
	}

	public void change_subfilters_foldout(presubfilter_class presubfilter, bool invert)
	{
		for (int i = 0; i < presubfilter.subfilter_index.Count; i++)
		{
			if (!invert)
			{
				subfilter[presubfilter.subfilter_index[i]].foldout = presubfilter.subfilters_foldout;
			}
			else
			{
				subfilter[presubfilter.subfilter_index[i]].foldout = !subfilter[presubfilter.subfilter_index[i]].foldout;
			}
		}
	}

	public void change_terrains_active(bool invert)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			if (!invert)
			{
				terrains[i].active = terrains_active;
			}
			else
			{
				terrains[i].active = !terrains[i].active;
			}
		}
	}

	public void change_meshes_active(bool invert)
	{
		for (int i = 0; i < meshes.Count; i++)
		{
			if (!invert)
			{
				meshes[i].active = meshes_active;
			}
			else
			{
				meshes[i].active = !meshes[i].active;
			}
		}
	}

	public void change_terrains_foldout(bool invert)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			if (!invert)
			{
				terrains[i].foldout = terrains_foldout2;
			}
			else
			{
				terrains[i].foldout = !terrains[i].foldout;
			}
		}
	}

	public void change_meshes_foldout(bool invert)
	{
		for (int i = 0; i < meshes.Count; i++)
		{
			if (!invert)
			{
				meshes[i].foldout = meshes_foldout2;
			}
			else
			{
				meshes[i].foldout = !meshes[i].foldout;
			}
		}
	}

	public void change_trees_active(tree_output_class tree_output, bool invert)
	{
		for (int i = 0; i < tree_output.tree.Count; i++)
		{
			if (!invert)
			{
				tree_output.tree_value.active[i] = tree_output.trees_active;
			}
			else
			{
				tree_output.tree_value.active[i] = !tree_output.tree_value.active[i];
			}
		}
		tree_output.tree_value.calc_value();
	}

	public void change_trees_foldout(tree_output_class tree_output, bool invert)
	{
		for (int i = 0; i < tree_output.tree.Count; i++)
		{
			if (!invert)
			{
				tree_output.tree[i].foldout = tree_output.trees_foldout;
			}
			else
			{
				tree_output.tree[i].foldout = !tree_output.tree[i].foldout;
			}
		}
	}

	public void change_trees_settings_foldout(terrain_class preterrain1, bool invert)
	{
		for (int i = 0; i < preterrain1.treePrototypes.Count; i++)
		{
			if (!invert)
			{
				preterrain1.treePrototypes[i].foldout = preterrain1.trees_foldout;
			}
			else
			{
				preterrain1.treePrototypes[i].foldout = !preterrain1.treePrototypes[i].foldout;
			}
		}
	}

	public void change_splats_settings_foldout(terrain_class preterrain1, bool invert)
	{
		for (int i = 0; i < preterrain1.splatPrototypes.Count; i++)
		{
			if (!invert)
			{
				preterrain1.splatPrototypes[i].foldout = preterrain1.splats_foldout;
			}
			else
			{
				preterrain1.splatPrototypes[i].foldout = !preterrain1.splatPrototypes[i].foldout;
			}
		}
	}

	public void change_color_splats_settings_foldout(terrain_class preterrain1, bool invert)
	{
		for (int i = 0; i < settings.color_splatPrototypes.Length; i++)
		{
			if (!invert)
			{
				settings.color_splatPrototypes[i].foldout = preterrain1.splats_foldout;
			}
			else
			{
				settings.color_splatPrototypes[i].foldout = !settings.color_splatPrototypes[i].foldout;
			}
		}
	}

	public void change_details_settings_foldout(terrain_class preterrain1, bool invert)
	{
		for (int i = 0; i < preterrain1.detailPrototypes.Count; i++)
		{
			if (!invert)
			{
				preterrain1.detailPrototypes[i].foldout = preterrain1.details_foldout;
			}
			else
			{
				preterrain1.detailPrototypes[i].foldout = !preterrain1.detailPrototypes[i].foldout;
			}
		}
	}

	public void change_objects_active(object_output_class object_output, bool invert)
	{
		for (int i = 0; i < object_output.@object.Count; i++)
		{
			if (!invert)
			{
				object_output.object_value.active[i] = object_output.objects_active;
			}
			else
			{
				object_output.object_value.active[i] = !object_output.object_value.active[i];
			}
		}
		object_output.object_value.calc_value();
	}

	public void change_objects_foldout(object_output_class object_output, bool invert)
	{
		for (int i = 0; i < object_output.@object.Count; i++)
		{
			if (!invert)
			{
				object_output.@object[i].foldout = object_output.objects_foldout;
			}
			else
			{
				object_output.@object[i].foldout = !object_output.@object[i].foldout;
			}
		}
	}

	public void change_color_ranges_active(precolor_range_class precolor_range, bool invert)
	{
		for (int i = 0; i < precolor_range.color_range.Count; i++)
		{
			if (!invert)
			{
				precolor_range.color_range_value.active[i] = precolor_range.color_ranges_active;
			}
			else
			{
				precolor_range.color_range_value.active[i] = !precolor_range.color_range_value.active[i];
			}
		}
	}

	public void erase_subfilters(filter_class filter)
	{
		int count = filter.presubfilter.subfilter_index.Count;
		int num = default(int);
		for (int i = 0; i < count; i++)
		{
			erase_subfilter(0, filter.presubfilter);
		}
	}

	public void add_subfilter(int subfilter_number, presubfilter_class presubfilter)
	{
		subfilter.Add(new subfilter_class());
		presubfilter.subfilter_index.Insert(subfilter_number, subfilter.Count - 1);
		if (terrains.Count > 1)
		{
			subfilter[subfilter.Count - 1].preimage.image_mode = image_mode_enum.MultiTerrain;
		}
		presubfilter.set_subfilter_text();
	}

	public void add_line_point(List<line_list_class> line_list, int line_point_number)
	{
		line_list.Insert(line_point_number, new line_list_class());
	}

	public void erase_line_point(List<line_list_class> line_list, int line_point_number)
	{
		line_list.RemoveAt(line_point_number);
	}

	public void erase_subfilter(int subfilter_number, presubfilter_class presubfilter)
	{
		if (presubfilter.subfilter_index.Count > 0)
		{
			int num = presubfilter.subfilter_index[subfilter_number];
			swap_subfilter2(num, subfilter.Count - 1, blink: false);
			subfilter.RemoveAt(subfilter.Count - 1);
			presubfilter.subfilter_index.RemoveAt(subfilter_number);
			relink_subfilter_index(num);
			presubfilter.set_subfilter_text();
		}
	}

	public void erase_subfilter_reference(presubfilter_class presubfilter, int subfilter_index)
	{
		presubfilter.subfilter_index.RemoveAt(subfilter_index);
		presubfilter.set_subfilter_text();
	}

	public void erase_subfilter_unlinked(int subfilter_number)
	{
		swap_subfilter2(subfilter_number, subfilter.Count - 1, blink: false);
		subfilter.RemoveAt(subfilter.Count - 1);
		relink_subfilter_index(subfilter_number);
	}

	public void swap_subfilter(presubfilter_class presubfilter1, int subfilter_index1, presubfilter_class presubfilter2, int subfilter_index2)
	{
		if (subfilter_index2 >= 0 && subfilter_index2 <= presubfilter2.subfilter_index.Count - 1)
		{
			subfilter_class value = subfilter[presubfilter1.subfilter_index[subfilter_index1]];
			subfilter[presubfilter1.subfilter_index[subfilter_index1]] = subfilter[presubfilter2.subfilter_index[subfilter_index2]];
			subfilter[presubfilter2.subfilter_index[subfilter_index2]] = value;
			if (!(subfilter[presubfilter1.subfilter_index[subfilter_index1]].color_subfilter[0] >= 1.5f))
			{
				subfilter[presubfilter1.subfilter_index[subfilter_index1]].color_subfilter = subfilter[presubfilter1.subfilter_index[subfilter_index1]].color_subfilter + new Color(1f, 1f, 1f, 1f);
			}
			if (!(subfilter[presubfilter2.subfilter_index[subfilter_index2]].color_subfilter[0] >= 1.5f))
			{
				subfilter[presubfilter2.subfilter_index[subfilter_index2]].color_subfilter = subfilter[presubfilter2.subfilter_index[subfilter_index2]].color_subfilter + new Color(1f, 1f, 1f, 1f);
			}
		}
	}

	public void swap_subfilter2(int subfilter_number1, int subfilter_number2, bool blink)
	{
		subfilter_class value = subfilter[subfilter_number1];
		subfilter[subfilter_number1] = subfilter[subfilter_number2];
		subfilter[subfilter_number2] = value;
		if (blink)
		{
			if (!(subfilter[subfilter_number1].color_subfilter[0] >= 1.5f))
			{
				subfilter[subfilter_number1].color_subfilter = subfilter[subfilter_number1].color_subfilter + new Color(1f, 1f, 1f, 1f);
			}
			if (!(subfilter[subfilter_number2].color_subfilter[0] >= 1.5f))
			{
				subfilter[subfilter_number2].color_subfilter = subfilter[subfilter_number2].color_subfilter + new Color(1f, 1f, 1f, 1f);
			}
		}
	}

	public void new_layers()
	{
		filter.Clear();
		subfilter.Clear();
		prelayers.Clear();
		reset_swapcopy();
		disable_outputs();
		prelayers.Add(new prelayer_class(0, 0));
		prelayer = prelayers[0];
		prelayer.prearea.active = false;
		filename = string.Empty;
		set_area_resolution(terrains[0], prelayer.prearea);
		settings.colormap = false;
		count_layers();
	}

	public void reset_swapcopy()
	{
		swap_layer_select = false;
		swap_filter_select = false;
		swap_subfilter_select = false;
		swap_object_select = false;
		swap_color_range_select = false;
		swap_description_select = false;
		copy_layer_select = false;
		copy_filter_select = false;
		copy_subfilter_select = false;
		copy_object_select = false;
		copy_color_range_select = false;
		copy_description_select = false;
		for (int i = 0; i < filter.Count; i++)
		{
			for (int j = 0; j < filter[i].precurve_list.Count; j++)
			{
				filter[i].precurve_list[j].curve_text = "Curve";
			}
		}
		for (int k = 0; k < subfilter.Count; k++)
		{
			for (int j = 0; j < subfilter[k].precurve_list.Count; j++)
			{
				subfilter[k].precurve_list[j].curve_text = "Curve";
			}
		}
	}

	public void reset_software_version()
	{
		software_id = 0f;
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				prelayers[i].layer[j].software_id = 0f;
			}
		}
	}

	public int get_output_length(layer_class layer)
	{
		return (layer.output != 0) ? ((layer.output != layer_output_enum.color) ? ((layer.output == layer_output_enum.splat) ? layer.splat_output.splat.Count : ((layer.output == layer_output_enum.tree) ? layer.tree_output.tree.Count : ((layer.output == layer_output_enum.grass) ? layer.grass_output.grass.Count : ((layer.output != layer_output_enum.@object) ? (-1) : layer.object_output.@object.Count)))) : 0) : 0;
	}

	public void set_view_only_selected(prelayer_class prelayer, layer_output_enum selected, bool disable_view)
	{
		if (disable_view)
		{
			prelayer.view_heightmap_layer = (prelayer.view_color_layer = (prelayer.view_splat_layer = (prelayer.view_tree_layer = (prelayer.view_grass_layer = (prelayer.view_object_layer = false)))));
		}
		if (selected == layer_output_enum.heightmap)
		{
			prelayer.view_heightmap_layer = true;
		}
		if (selected == layer_output_enum.color)
		{
			prelayer.view_color_layer = true;
		}
		if (selected == layer_output_enum.splat)
		{
			prelayer.view_splat_layer = true;
		}
		if (selected == layer_output_enum.tree)
		{
			prelayer.view_tree_layer = true;
		}
		if (selected == layer_output_enum.grass)
		{
			prelayer.view_grass_layer = true;
		}
		if (selected == layer_output_enum.@object)
		{
			prelayer.view_object_layer = true;
		}
	}

	public void set_output(layer_output_enum selected)
	{
		if (selected == layer_output_enum.heightmap)
		{
			disable_outputs();
			heightmap_output = true;
		}
		if (selected == layer_output_enum.color)
		{
			disable_outputs();
			color_output = true;
		}
		if (selected == layer_output_enum.splat)
		{
			disable_outputs();
			splat_output = true;
		}
		if (selected == layer_output_enum.tree)
		{
			disable_outputs();
			tree_output = true;
		}
		if (selected == layer_output_enum.grass)
		{
			disable_outputs();
			grass_output = true;
		}
		if (selected == layer_output_enum.@object)
		{
			disable_outputs();
			object_output = true;
		}
	}

	public bool swap_search_layer(prelayer_class prelayer1, prelayer_class prelayer2, layer_class layer, string text1, string text2)
	{
		int i;
		if (prelayer2.index > 0)
		{
			for (i = 0; i < prelayer1.layer.Count; i++)
			{
				for (int j = 0; j < prelayer1.layer[i].object_output.@object.Count; j++)
				{
					if (!prelayer1.layer[i].object_output.@object[j].prelayer_created)
					{
						continue;
					}
					int num = 0;
					while (num < prelayers[prelayer1.layer[i].object_output.@object[j].prelayer_index].layer.Count)
					{
						if (RuntimeServices.EqualityOperator(prelayers[prelayer1.layer[i].object_output.@object[j].prelayer_index].layer[num], layer))
						{
							prelayer1.layer[i].swap_text = prelayer1.layer[i].swap_text.Replace(text1, text2);
						}
						if (prelayers[prelayer1.layer[i].object_output.@object[j].prelayer_index].layer.Count <= 0 || !swap_search_layer(prelayers[prelayer1.layer[i].object_output.@object[j].prelayer_index], prelayer2, layer, text1, text2))
						{
							num++;
							continue;
						}
						goto IL_0139;
					}
				}
			}
		}
		int result = 0;
		goto IL_01eb;
		IL_01eb:
		return (byte)result != 0;
		IL_0139:
		prelayer1.layer[i].swap_text = prelayer1.layer[i].swap_text.Replace(text1, text2);
		result = 1;
		goto IL_01eb;
	}

	public void set_area_cube(int terrain_number)
	{
		terrain_class terrain_class = terrains[terrain_number];
		Vector3 localScale = default(Vector3);
		Vector3 size = terrain_class.terrain.terrainData.size;
		float num = size.x / resolution;
		Vector3 size2 = terrain_class.terrain.terrainData.size;
		float num2 = size2.z / resolution;
		Vector3 vector = terrain_class.terrain.transform.position;
		localScale.x = (terrain_class.prearea.area.xMax - terrain_class.prearea.area.x) * num;
		localScale.z = (terrain_class.prearea.area.yMax - terrain_class.prearea.area.y) * num2;
		localScale.y = 50f;
		vector.x += terrain_class.prearea.area.x * num + localScale.x / 2f;
		vector.z += terrain_class.prearea.area.y * num2 + localScale.z / 2f;
		Vector3 vector2 = transform.position;
		vector.y = vector2.y;
		transform.position = vector;
		transform.localScale = localScale;
	}

	public void calc_area_max(area_class prearea)
	{
		Rect area_max = default(Rect);
		area_max.width = terrains[0].tiles.x * terrains[0].size.x;
		area_max.height = terrains[0].tiles.y * terrains[0].size.z;
		int index = default(int);
		for (int i = 0; i < terrains.Count; i++)
		{
			if (terrains[i].tile_z == 0f && terrains[i].tile_x == 0f)
			{
				index = i;
				if (!terrains[i].terrain)
				{
					return;
				}
				break;
			}
		}
		Vector3 vector = terrains[index].terrain.transform.position;
		area_max.x = vector.x;
		Vector3 vector2 = terrains[index].terrain.transform.position;
		area_max.y = vector2.z;
		prearea.area_max = area_max;
		prearea.round_area_to_step(prearea.area_max);
		correct_area_max(prearea);
	}

	public void correct_area_max(area_class prearea)
	{
		if (!(prearea.area.xMin >= prearea.area_max.xMin))
		{
			prearea.area.xMin = prearea.area_max.xMin;
		}
		if (!(prearea.area.xMax <= prearea.area_max.xMax))
		{
			prearea.area.xMax = prearea.area_max.xMax;
		}
		if (!(prearea.area.yMin >= prearea.area_max.yMin))
		{
			prearea.area.yMin = prearea.area_max.yMin;
		}
		if (!(prearea.area.yMax <= prearea.area_max.yMax))
		{
			prearea.area.yMax = prearea.area_max.yMax;
		}
	}

	public void set_terrain_length(int length_new)
	{
		if (length_new != terrains.Count)
		{
			if (length_new > terrains.Count)
			{
				terrains.Add(new terrain_class());
				if (terrains.Count > 1)
				{
					terrains[terrains.Count - 1].size = terrains[terrains.Count - 2].size;
					terrains[terrains.Count - 1].heightmap_resolution_list = terrains[terrains.Count - 2].heightmap_resolution_list;
					terrains[terrains.Count - 1].splatmap_resolution_list = terrains[terrains.Count - 2].splatmap_resolution_list;
					terrains[terrains.Count - 1].basemap_resolution_list = terrains[terrains.Count - 2].basemap_resolution_list;
					terrains[terrains.Count - 1].detailmap_resolution_list = terrains[terrains.Count - 2].detailmap_resolution_list;
					terrains[terrains.Count - 1].detail_resolution_per_patch_list = terrains[terrains.Count - 2].detail_resolution_per_patch_list;
					set_terrain_resolution_from_list(terrains[terrains.Count - 1]);
				}
				terrains[terrains.Count - 1].prearea.area.xMax = resolution;
				terrains[terrains.Count - 1].prearea.area.yMax = resolution;
				terrains[terrains.Count - 1].index = terrains.Count - 1;
			}
			else
			{
				terrains.RemoveAt(terrains.Count - 1);
			}
		}
		if (terrains.Count == 1)
		{
			terrains[0].tile_x = 0f;
			terrains[0].tile_z = 0f;
			terrains[0].tiles = new Vector2(1f, 1f);
		}
		calc_terrain_one_more_tile();
		set_smooth_tool_terrain_popup();
		set_terrain_text();
	}

	public void add_terrain(int terrain_number)
	{
		terrains.Insert(terrain_number, new terrain_class());
		terrains[terrains.Count - 1].prearea.area.xMax = resolution;
		terrains[terrains.Count - 1].prearea.area.yMax = resolution;
		terrains[terrains.Count - 1].index = terrain_number;
		set_smooth_tool_terrain_popup();
		set_terrain_text();
	}

	public void SetTerrainDefault(terrain_class preterrain)
	{
		preterrain.size = new Vector3(1000f, 500f, 1000f);
	}

	public void clear_terrains()
	{
		terrains.Clear();
		add_terrain(0);
		SetTerrainDefault(terrains[0]);
	}

	public void clear_meshes()
	{
		meshes.Clear();
		meshes.Add(new mesh_class());
	}

	public void clear_terrain_list(bool deleteTerrainHierarchy)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			if (deleteTerrainHierarchy)
			{
				DeleteTerrain(terrains[i]);
			}
			if (i > 0)
			{
				terrains.RemoveAt(i);
				i--;
			}
		}
	}

	public void DeleteTerrain(terrain_class preterrain)
	{
		if (preterrain.terrain != null)
		{
			UnityEngine.Object.Destroy(preterrain.terrain.gameObject);
		}
	}

	public void set_terrain_text()
	{
		if (terrains.Count > 1)
		{
			terrain_text = "Terrains(" + terrains.Count + ")";
		}
		else
		{
			terrain_text = "Terrain(" + terrains.Count + ")";
		}
	}

	public bool erase_raw_file(int raw_file_index)
	{
		int result;
		if (raw_file_index < raw_files.Count)
		{
			raw_files[raw_file_index] = raw_files[raw_files.Count - 1];
			raw_files.RemoveAt(raw_files.Count - 1);
			loop_raw_file(raw_file_index, check_double: false, relink: true, mark_linked: false);
			result = 1;
		}
		else
		{
			result = 0;
		}
		return (byte)result != 0;
	}

	public int check_raw_file_in_list(string file)
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < raw_files.Count)
			{
				if (file.ToLower() == raw_files[num].file.ToLower())
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public void strip_auto_search_file(auto_search_class auto_search)
	{
		string format = new string("0"[0], auto_search.digits);
		string text = auto_search.format.Replace("%x", auto_search.start_x.ToString(format));
		text = text.Replace("%y", auto_search.start_y.ToString(format));
		text = text.Replace("%n", auto_search.start_n.ToString(format));
		auto_search.filename = Path.GetFileNameWithoutExtension(auto_search.path_full).Replace(text, string.Empty);
		auto_search.extension = Path.GetExtension(auto_search.path_full);
		if (auto_search.extension.Length != 0)
		{
			auto_search.filename = auto_search.filename.Replace(auto_search.extension, string.Empty);
		}
	}

	public void clean_raw_file_list()
	{
		loop_raw_file(0, check_double: false, relink: false, mark_linked: true);
		for (int i = 0; i < raw_files.Count; i++)
		{
			if (!raw_files[i].linked)
			{
				erase_raw_file(i);
			}
		}
	}

	public bool loop_raw_file(int raw_file_index, bool check_double, bool relink, bool mark_linked)
	{
		int num = 0;
		int num2 = 0;
		if (mark_linked)
		{
			for (int i = 0; i < raw_files.Count; i++)
			{
				if (!raw_files[i].created)
				{
					raw_files[i].linked = false;
				}
			}
		}
		int num3 = 0;
		int result;
		while (true)
		{
			if (num3 < terrains.Count)
			{
				if (terrains[num3].raw_file_index > -1)
				{
					if (mark_linked)
					{
						raw_files[terrains[num3].raw_file_index].linked = true;
					}
					if (check_double)
					{
						if (terrains[num3].raw_file_index == raw_file_index)
						{
							num++;
						}
						if (num > 1)
						{
							result = 1;
							break;
						}
					}
					if (relink && terrains[num3].raw_file_index == raw_files.Count)
					{
						terrains[num3].raw_file_index = raw_file_index;
					}
				}
				num3++;
				continue;
			}
			int num4 = 0;
			while (true)
			{
				if (num4 < filter.Count)
				{
					if (filter[num4].raw != null)
					{
						for (num2 = 0; num2 < filter[num4].raw.file_index.Count; num2++)
						{
							if (filter[num4].raw.file_index[num2] <= -1)
							{
								continue;
							}
							if (mark_linked)
							{
								raw_files[filter[num4].raw.file_index[num2]].linked = true;
							}
							if (check_double)
							{
								if (filter[num4].raw.file_index[num2] == raw_file_index)
								{
									num++;
								}
								if (num > 1)
								{
									goto IL_01cd;
								}
							}
							if (relink && filter[num4].raw.file_index[num2] == raw_files.Count)
							{
								filter[num4].raw.file_index[num2] = raw_file_index;
							}
						}
					}
					num4++;
					continue;
				}
				int num5 = 0;
				while (true)
				{
					if (num5 < subfilter.Count)
					{
						if (subfilter[num5].raw != null)
						{
							for (num2 = 0; num2 < subfilter[num5].raw.file_index.Count; num2++)
							{
								if (subfilter[num5].raw.file_index[num2] <= -1)
								{
									continue;
								}
								if (mark_linked)
								{
									raw_files[subfilter[num5].raw.file_index[num2]].linked = true;
								}
								if (check_double)
								{
									if (subfilter[num5].raw.file_index[num2] == raw_file_index)
									{
										num++;
									}
									if (num > 1)
									{
										goto IL_0317;
									}
								}
								if (relink && subfilter[num5].raw.file_index[num2] == raw_files.Count)
								{
									subfilter[num5].raw.file_index[num2] = raw_file_index;
								}
							}
						}
						num5++;
						continue;
					}
					result = 0;
					break;
					IL_0317:
					result = 1;
					break;
				}
				break;
				IL_01cd:
				result = 1;
				break;
			}
			break;
		}
		return (byte)result != 0;
	}

	public void reset_raw_file(int index)
	{
		for (int i = 0; i < filter.Count; i++)
		{
			if (RuntimeServices.EqualityOperator(filter[i].raw, null))
			{
				continue;
			}
			for (int j = 0; j < filter[i].raw.file_index.Count; j++)
			{
				if (filter[i].raw.file_index[j] == index)
				{
					filter[i].raw.file_index[j] = -1;
				}
			}
		}
		for (int i = 0; i < subfilter.Count; i++)
		{
			if (RuntimeServices.EqualityOperator(subfilter[i].raw, null))
			{
				continue;
			}
			for (int j = 0; j < subfilter[i].raw.file_index.Count; j++)
			{
				if (subfilter[i].raw.file_index[j] == index)
				{
					subfilter[i].raw.file_index[j] = -1;
				}
			}
		}
	}

	public void reset_all_outputs()
	{
		terrain_reset_heightmap(terrains[0], all: true);
		terrain_all_reset_splat();
		terrain_reset_trees(terrains[0], all: true);
		terrain_reset_grass(terrains[0], all: true);
		terrain_reset_heightmap(terrains[0], all: true);
		loop_prelayer("(cpo)", 0, loop_inactive: true);
	}

	public void terrain_reset_heightmap(terrain_class preterrain1, bool all)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		float[,] array = (float[,])System.Array.CreateInstance(typeof(float), new int[2]
		{
			preterrain1.terrain.terrainData.heightmapResolution,
			preterrain1.terrain.terrainData.heightmapResolution
		});
		if (!all)
		{
			if ((bool)preterrain1.terrain)
			{
				preterrain1.terrain.terrainData.SetHeights(0, 0, array);
				preterrain1.color_terrain = new Color(0.5f, 0.5f, 1f, 1f);
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				if ((float)terrains[i].terrain.terrainData.heightmapResolution != Mathf.Sqrt(array.Length))
				{
					array = (float[,])System.Array.CreateInstance(typeof(float), new int[2]
					{
						terrains[i].terrain.terrainData.heightmapResolution,
						terrains[i].terrain.terrainData.heightmapResolution
					});
				}
				terrains[i].terrain.terrainData.SetHeights(0, 0, array);
				terrains[i].color_terrain = new Color(0.5f, 0.5f, 1f, 1f);
			}
		}
	}

	public void terrain_reset_splat(terrain_class preterrain1)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		assign_terrain_splat_alpha(preterrain1);
		if (preterrain1.splat_alpha == null)
		{
			return;
		}
		if (preterrain1.splat_alpha.Length > 0)
		{
			texture_fill(preterrain1.splat_alpha[0], new Color(1f, 0f, 0f, 0f), apply: true);
		}
		if (preterrain1.splat_alpha.Length > 1)
		{
			for (int i = 1; i < preterrain1.splat_alpha.Length; i++)
			{
				texture_fill(preterrain1.splat_alpha[i], new Color(0f, 0f, 0f, 0f), apply: true);
			}
		}
		preterrain1.terrain.terrainData.SetAlphamaps(0, 0, preterrain1.terrain.terrainData.GetAlphamaps(0, 0, 1, 1));
		preterrain1.color_terrain = new Color(0.5f, 0.5f, 1f, 1f);
	}

	public void terrain_all_reset_splat()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			terrain_reset_splat(terrains[i]);
		}
	}

	public void texture_fill(Texture2D texture, Color color, bool apply)
	{
		if (texture == null)
		{
			return;
		}
		int width = texture.width;
		int num = texture.height;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < width; j++)
			{
				texture.SetPixel(j, i, color);
			}
		}
		if (apply)
		{
			texture.Apply();
		}
	}

	public void terrain_reset_trees(terrain_class preterrain1, bool all)
	{
		if (!all)
		{
			if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData)
			{
				preterrain1.terrain.terrainData.treeInstances = new TreeInstance[0];
				preterrain1.color_terrain = new Color(0.5f, 0.5f, 1f, 1f);
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain && (bool)terrains[i].terrain.terrainData)
			{
				terrains[i].terrain.terrainData.treeInstances = new TreeInstance[0];
				terrains[i].terrain.Flush();
				terrains[i].color_terrain = new Color(0.5f, 0.5f, 1f, 1f);
			}
		}
	}

	public void terrain_reset_grass(terrain_class preterrain1, bool all)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		int[,] array = (int[,])System.Array.CreateInstance(typeof(int), new int[2]
		{
			preterrain1.terrain.terrainData.detailResolution,
			preterrain1.terrain.terrainData.detailResolution
		});
		int num = default(int);
		if (!all)
		{
			if ((bool)preterrain1.terrain)
			{
				for (num = 0; num < preterrain1.terrain.terrainData.detailPrototypes.Length; num++)
				{
					preterrain1.terrain.terrainData.SetDetailLayer(0, 0, num, array);
				}
				preterrain1.color_terrain = new Color(0.5f, 0.5f, 1f, 1f);
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				if ((float)terrains[i].terrain.terrainData.detailResolution != Mathf.Sqrt(array.Length))
				{
					array = (int[,])System.Array.CreateInstance(typeof(int), new int[2]
					{
						terrains[i].terrain.terrainData.detailResolution,
						terrains[i].terrain.terrainData.detailResolution
					});
				}
				for (num = 0; num < terrains[i].terrain.terrainData.detailPrototypes.Length; num++)
				{
					terrains[i].terrain.terrainData.SetDetailLayer(0, 0, num, array);
				}
				terrains[i].color_terrain = new Color(0.5f, 0.5f, 1f, 1f);
			}
		}
	}

	public bool terrains_check_double(terrain_class preterrain)
	{
		bool result = false;
		for (int i = 0; i < terrains.Count; i++)
		{
			if (terrains[i].terrain == preterrain.terrain && preterrain.terrain != null && !RuntimeServices.EqualityOperator(terrains[i], preterrain))
			{
				preterrain.terrain = null;
				result = true;
			}
		}
		return result;
	}

	public void erase_terrain(int number)
	{
		if (terrains.Count > 1)
		{
			terrains.RemoveAt(number);
		}
		else
		{
			terrains[number] = null;
		}
		if (terrains.Count == 1)
		{
			terrains[0].tile_x = 0f;
			terrains[0].tile_z = 0f;
			terrains[0].tiles = new Vector2(1f, 1f);
		}
		set_smooth_tool_terrain_popup();
		set_terrain_text();
	}

	public void restore_references()
	{
		GameObject gameObject = null;
		for (int i = 0; i < terrains.Count; i++)
		{
			GameObject gameObject2 = null;
			if (terrains[i].name != string.Empty)
			{
				gameObject2 = GameObject.Find(terrains[i].name);
				if ((bool)gameObject2)
				{
					terrains[i].terrain = (Terrain)gameObject2.GetComponent(typeof(Terrain));
				}
			}
		}
		for (int j = 0; j < prelayers.Count; j++)
		{
			for (int k = 0; k < prelayers[j].layer.Count; k++)
			{
				for (int l = 0; l < prelayers[j].layer[k].object_output.@object.Count; l++)
				{
					object_class object_class = prelayers[j].layer[k].object_output.@object[l];
					if (object_class.name != string.Empty && !object_class.object1)
					{
						object_class.object1 = GameObject.Find(object_class.name);
					}
					if (object_class.parent_name != string.Empty && !object_class.parent)
					{
						gameObject = GameObject.Find(object_class.parent_name);
						if ((bool)gameObject)
						{
							object_class.parent = gameObject.transform;
						}
					}
				}
			}
		}
	}

	public void set_references()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].name = terrains[i].terrain.name;
			}
		}
		for (int j = 0; j < prelayers.Count; j++)
		{
			for (int k = 0; k < prelayers[j].layer.Count; k++)
			{
				for (int l = 0; l < prelayers[j].layer[k].object_output.@object.Count; l++)
				{
					object_class object_class = prelayers[j].layer[k].object_output.@object[l];
					if ((bool)object_class.object1)
					{
						object_class.name = object_class.object1.name;
					}
					if ((bool)object_class.parent)
					{
						object_class.parent_name = object_class.parent.name;
					}
				}
			}
		}
	}

	public float calc_color_pos(Color color, Color color_start, Color color_end)
	{
		Color color2 = color_start;
		Color color3 = default(Color);
		float num = default(float);
		float num2 = default(float);
		if (!(color_start.r <= color_end.r))
		{
			color_start.r = color_end.r;
			color_end.r = color2.r;
		}
		if (!(color_start.g <= color_end.g))
		{
			color_start.g = color_end.g;
			color_end.g = color2.g;
		}
		if (!(color_start.b <= color_end.b))
		{
			color_start.b = color_end.b;
			color_end.b = color2.b;
		}
		color3 = color_end - color_start;
		color -= color_start;
		float result;
		if (color.r < 0f || color.g < 0f || !(color.b >= 0f))
		{
			result = 0f;
		}
		else if (color.r > color3.r || color.g > color3.g || !(color.b <= color3.b))
		{
			result = 0f;
		}
		else
		{
			num += color3.r + color3.g + color3.b;
			num2 += color.r + color.g + color.b;
			result = ((num == 0f) ? 1f : (num2 / num));
		}
		return result;
	}

	public bool color_in_range(Color color, Color color_start, Color color_end)
	{
		Color color2 = color_start;
		if (!(color_start.r <= color_end.r))
		{
			color_start.r = color_end.r;
			color_end.r = color2.r;
		}
		if (!(color_start.g <= color_end.g))
		{
			color_start.g = color_end.g;
			color_end.g = color2.g;
		}
		if (!(color_start.b <= color_end.b))
		{
			color_start.b = color_end.b;
			color_end.b = color2.b;
		}
		return (!(color.r < color_start.r) && !(color.r > color_end.r) && !(color.g < color_start.g) && !(color.g > color_end.g) && !(color.b < color_start.b) && !(color.b > color_end.b)) ? true : false;
	}

	public Color random_color_from_range(Color color_start, Color color_end)
	{
		Color result = default(Color);
		AnimationCurve animationCurve = AnimationCurve.Linear(0f, color_start.r, 1f, color_end.r);
		AnimationCurve animationCurve2 = AnimationCurve.Linear(0f, color_start.g, 1f, color_end.g);
		AnimationCurve animationCurve3 = AnimationCurve.Linear(0f, color_start.b, 1f, color_end.b);
		float time = UnityEngine.Random.Range(0f, 1f);
		result.r = animationCurve.Evaluate(time);
		result.g = animationCurve2.Evaluate(time);
		result.b = animationCurve3.Evaluate(time);
		result.a = 1f;
		return result;
	}

	public void convert_16to8_bit(float value)
	{
		value *= 65535f;
		ushort num = (ushort)value;
		byte_hi = (int)((uint)num >> 8);
		byte_lo = num - (byte_hi << 8);
	}

	public void convert_24to8_bit(float value)
	{
		value *= 8388608f;
		uint num = (uint)value;
		byte_hi2 = (int)(num >> 16);
		byte_hi = (int)((long)(int)num - (long)(byte_hi2 << 16) >> 8);
		byte_lo = (int)((long)(int)num - (long)(byte_hi2 << 16) - (byte_hi << 8));
	}

	public int export_meshcapture()
	{
		int result;
		if (!meshcapture_tool_object)
		{
			result = -1;
		}
		else
		{
			MeshFilter[] componentsInChildren = meshcapture_tool_object.GetComponentsInChildren<MeshFilter>();
			Vector3[] array = null;
			meshcapture_tool_image = new Texture2D(meshcapture_tool_image_width, meshcapture_tool_image_height);
			Vector3[] array2 = new Vector3[3];
			int[] array3 = null;
			Mesh mesh = null;
			Vector3 vector = default(Vector3);
			Vector3 vector2 = default(Vector3);
			Transform transform = null;
			meshcapture_tool_image.wrapMode = TextureWrapMode.Clamp;
			vector = ((!meshcapture_tool_pivot) ? meshcapture_tool_object.transform.position : meshcapture_tool_pivot.position);
			if (componentsInChildren != null)
			{
				Color[] array4 = new Color[meshcapture_tool_image_width * meshcapture_tool_image_height];
				int i = 0;
				Color[] array5 = array4;
				for (int length = array5.Length; i < length; i++)
				{
					array5[i] = meshcapture_background_color;
				}
				meshcapture_tool_image.SetPixels(array4);
				int j = 0;
				MeshFilter[] array6 = componentsInChildren;
				for (int length2 = array6.Length; j < length2; j++)
				{
					mesh = ((MeshFilter)array6[j].GetComponent(typeof(MeshFilter))).sharedMesh;
					if (!mesh)
					{
						continue;
					}
					array = mesh.vertices;
					array3 = mesh.triangles;
					transform = array6[j].gameObject.transform;
					Vector3[] normals = mesh.normals;
					for (int k = 0; k < array3.Length / 3; k++)
					{
						int num = array3[k * 3];
						int num2 = array3[k * 3 + 1];
						int num3 = array3[k * 3 + 2];
						array2[0] = transform.TransformPoint(array[num]) - vector;
						array2[1] = transform.TransformPoint(array[num2]) - vector;
						array2[2] = transform.TransformPoint(array[num3]) - vector;
						Vector3 vector3 = array2[0];
						Vector3 vector4 = normals[num];
						vector4.Normalize();
						vector3.Normalize();
						color1 = meshcapture_tool_color;
						if (meshcapture_tool_shadows)
						{
							color1.r = Mathf.Abs((vector4.x + vector4.y + vector4.z) / 3f);
							color1.g = Mathf.Abs((vector4.x + vector4.y + vector4.z) / 3f);
							color1.b = Mathf.Abs((vector4.x + vector4.y + vector4.z) / 3f);
							color1.r *= meshcapture_tool_color.r;
							color1.g *= meshcapture_tool_color.g;
							color1.b *= meshcapture_tool_color.b;
						}
						array2[0].x = array2[0].x * meshcapture_tool_scale;
						array2[0].z = array2[0].z * meshcapture_tool_scale;
						array2[0].y = array2[0].y * meshcapture_tool_scale;
						array2[0].x = array2[0].x + (float)(meshcapture_tool_image_width / 2);
						array2[0].z = array2[0].z + (float)(meshcapture_tool_image_height / 2);
						array2[0].y = array2[0].y + (float)(meshcapture_tool_image_height / 2);
						array2[1].x = array2[1].x * meshcapture_tool_scale;
						array2[1].z = array2[1].z * meshcapture_tool_scale;
						array2[1].y = array2[1].y * meshcapture_tool_scale;
						array2[1].x = array2[1].x + (float)(meshcapture_tool_image_width / 2);
						array2[1].z = array2[1].z + (float)(meshcapture_tool_image_height / 2);
						array2[1].y = array2[1].y + (float)(meshcapture_tool_image_height / 2);
						array2[2].x = array2[2].x * meshcapture_tool_scale;
						array2[2].z = array2[2].z * meshcapture_tool_scale;
						array2[2].y = array2[2].y * meshcapture_tool_scale;
						array2[2].x = array2[2].x + (float)(meshcapture_tool_image_width / 2);
						array2[2].z = array2[2].z + (float)(meshcapture_tool_image_height / 2);
						array2[2].y = array2[2].y + (float)(meshcapture_tool_image_height / 2);
						float num4 = 0f;
						float num5 = 700f;
						float num6 = 900f;
						Line(meshcapture_tool_image, (int)(array2[0].x - num4), (int)array2[0].z, (int)(array2[1].x - num4), (int)array2[1].z, color1);
						Line(meshcapture_tool_image, (int)(array2[0].x - num4), (int)array2[0].z, (int)(array2[2].x - num4), (int)array2[2].z, color1);
						Line(meshcapture_tool_image, (int)(array2[1].x - num4), (int)array2[1].z, (int)(array2[2].x - num4), (int)array2[2].z, color1);
					}
				}
				if (meshcapture_tool_save_scale)
				{
					Color color = convert_float_to_color(meshcapture_tool_scale);
					Color color2 = default(Color);
					color2 = meshcapture_tool_image.GetPixel(0, 0);
					color2[3] = color[0];
					meshcapture_tool_image.SetPixel(0, 0, color2);
					color2 = meshcapture_tool_image.GetPixel(1, 0);
					color2[3] = color[1];
					meshcapture_tool_image.SetPixel(1, 0, color2);
					color2 = meshcapture_tool_image.GetPixel(2, 0);
					color2[3] = color[2];
					meshcapture_tool_image.SetPixel(2, 0, color2);
					color2 = meshcapture_tool_image.GetPixel(3, 0);
					color2[3] = color[3];
					meshcapture_tool_image.SetPixel(3, 0, color2);
				}
				meshcapture_tool_image.Apply();
			}
			result = 1;
		}
		return result;
	}

	public void Line(Texture2D tex, int x0, int y0, int x1, int y1, Color col)
	{
		int num = y1 - y0;
		int num2 = x1 - x0;
		int num3 = default(int);
		int num4 = default(int);
		if (num < 0)
		{
			num = -num;
			num4 = -1;
		}
		else
		{
			num4 = 1;
		}
		if (num2 < 0)
		{
			num2 = -num2;
			num3 = -1;
		}
		else
		{
			num3 = 1;
		}
		num <<= 1;
		num2 <<= 1;
		tex.SetPixel(x0, y0, col);
		int num5;
		if (num2 > num)
		{
			num5 = num - (num2 >> 1);
			while (x0 != x1)
			{
				if (num5 >= 0)
				{
					y0 += num4;
					num5 -= num2;
				}
				x0 += num3;
				num5 += num;
				tex.SetPixel(x0, y0, col);
			}
			return;
		}
		num5 = num2 - (num >> 1);
		while (y0 != y1)
		{
			if (num5 >= 0)
			{
				x0 += num3;
				num5 -= num;
			}
			y0 += num4;
			num5 += num2;
			tex.SetPixel(x0, y0, col);
		}
	}

	public void texture_fill_color(Texture2D texture1, Color color)
	{
		float num = texture1.width * texture1.height;
		Color[] array = new Color[(int)num];
		int i = 0;
		Color[] array2 = array;
		for (int length = array2.Length; i < length; i++)
		{
			array2[i] = color;
		}
		texture1.SetPixels(0, 0, texture1.width, texture1.height, array);
	}

	public void tree_placed_reset()
	{
		for (int i = 0; i < prelayer.layer.Count; i++)
		{
			if (prelayer.layer[i].output == layer_output_enum.tree)
			{
				for (int j = 0; j < prelayer.layer[i].tree_output.tree.Count; j++)
				{
					prelayer.layer[i].tree_output.tree[j].placed = 0;
				}
			}
		}
	}

	public void disable_outputs()
	{
		heightmap_output = false;
		color_output = false;
		splat_output = false;
		tree_output = false;
		grass_output = false;
		object_output = false;
	}

	public bool check_treemap()
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < settings.treemap.Count)
			{
				if ((bool)settings.treemap[num].map && settings.treemap[num].load)
				{
					result = 1;
					break;
				}
				num++;
				continue;
			}
			result = 0;
			break;
		}
		return (byte)result != 0;
	}

	public bool check_grassmap()
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < settings.grassmap.Count)
			{
				if ((bool)settings.grassmap[num].map && settings.grassmap[num].load)
				{
					result = 1;
					break;
				}
				num++;
				continue;
			}
			result = 0;
			break;
		}
		return (byte)result != 0;
	}

	public int generate_begin_mesh()
	{
		prelayer = prelayers[0];
		UnityEngine.Random.seed = seed;
		prelayer.count_terrain = 0;
		for (int i = 0; i < meshes.Count; i++)
		{
			if (!meshes[i].gameObject || !meshes[i].meshFilter || !meshes[i].mesh || !meshes[i].active)
			{
				meshes.RemoveAt(i);
				i--;
			}
		}
		get_meshes_areas();
		calc_total_mesh_area();
		get_meshes_minmax_height();
		generate_pause = false;
		prelayer_stack.Add(0);
		link_placed_reference();
		loop_prelayer("(gfc)(slv)(ocr)(asr)(cpo)(ias)(eho)(st)(cmn)(ed)", 0, loop_inactive: false);
		int result;
		if (!find_mesh())
		{
			result = -1;
		}
		else if (prelayer.layer.Count == 0)
		{
			result = -2;
		}
		else
		{
			if (prelayers.Count > 1)
			{
				area_stack_enabled = true;
			}
			load_raw_heightmaps();
			generate_time_start = Time.realtimeSinceStartup;
			generate_time = 0f;
			tree_number = 0;
			auto_speed_time = Time.realtimeSinceStartup;
			generate_mesh_start();
			result = 1;
		}
		return result;
	}

	public int generate_begin()
	{
		if (heightmap_output && !color_output && !splat_output && !tree_output && !grass_output && !object_output)
		{
			only_heightmap = true;
		}
		prelayer = prelayers[0];
		UnityEngine.Random.seed = seed;
		prelayer.count_terrain = 0;
		generate_world_mode = prelayers[0].prearea.active;
		int num = 0;
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].index = i;
			terrains[i].index_old = num;
			num++;
			if (!terrains[i].terrain)
			{
				terrains.RemoveAt(i);
				i--;
			}
			else if (!terrains[i].terrain.terrainData)
			{
				terrains.RemoveAt(i);
				i--;
			}
		}
		assign_all_terrain_splat_alpha();
		int result;
		if (terrains.Count == 0)
		{
			result = -2;
		}
		else
		{
			get_terrains_position();
			int i = 0;
			while (true)
			{
				if (i < terrains.Count)
				{
					terrains[i].heightmap_resolution = terrains[i].terrain.terrainData.heightmapResolution;
					terrains[i].splatmap_resolution = terrains[i].terrain.terrainData.alphamapResolution;
					terrains[i].detail_resolution = terrains[i].terrain.terrainData.detailResolution;
					if (terrains[i].prearea.resolution_mode == resolution_mode_enum.Automatic)
					{
						select_automatic_step_resolution(terrains[i], terrains[i].prearea);
					}
					set_area_resolution(terrains[i], terrains[i].prearea);
					terrains[i].prearea.round_area_to_step(terrains[i].prearea.area);
					terrains[i].prearea.area_old = terrains[i].prearea.area;
					if (!world_output)
					{
						ref Rect area = ref terrains[i].prearea.area;
						float x = terrains[i].prearea.area.x;
						Vector3 vector = terrains[i].terrain.transform.position;
						area.x = x + vector.x;
						ref Rect area2 = ref terrains[i].prearea.area;
						float y = terrains[i].prearea.area.y;
						Vector3 vector2 = terrains[i].terrain.transform.position;
						area2.y = y + vector2.z;
					}
					if (!object_output)
					{
						terrains[i].prearea.area.xMax = terrains[i].prearea.area.xMax + terrains[i].prearea.step.x / 2f;
						terrains[i].prearea.area.yMin = terrains[i].prearea.area.yMin - terrains[i].prearea.step.y / 2f;
					}
					if (color_output)
					{
						terrains[i].color_length = 3;
						terrains[i].color = new float[3];
						terrains[i].color_layer = new float[3];
					}
					if (splat_output)
					{
						terrains[i].splat_length = terrains[i].terrain.terrainData.splatPrototypes.Length;
						if (terrains[i].splat_length == 0 && (color_output || splat_output))
						{
							preterrain = terrains[i];
							result = -3;
							break;
						}
						if (terrains[i].splat_length == 1 && splat_output)
						{
							preterrain = terrains[i];
							result = -5;
							break;
						}
						if (terrains[i].splat_length < terrains[0].splat_length)
						{
							preterrain = terrains[i];
							result = -7;
							break;
						}
						terrains[i].splat = new float[terrains[i].splat_length];
						terrains[i].splat_calc = new float[terrains[i].splat_length];
						terrains[i].splat_layer = new float[(int)(Mathf.Ceil((float)terrains[i].splat_length / 4f) * 4f)];
					}
					if (button_export && !export_texture)
					{
						export_texture = new Texture2D((int)terrains[0].prearea.resolution, (int)terrains[0].prearea.resolution, TextureFormat.RGB24, mipChain: false);
					}
					if (grass_output)
					{
						if (terrains[i].terrain.terrainData.detailPrototypes.Length < terrains[0].terrain.terrainData.detailPrototypes.Length)
						{
							preterrain = terrains[i];
							result = -8;
							break;
						}
						terrains[i].grass = new float[terrains[i].terrain.terrainData.detailPrototypes.Length];
					}
					i++;
					continue;
				}
				if (heightmap_output)
				{
					heights = (float[,])System.Array.CreateInstance(typeof(float), new int[2]
					{
						terrains[0].terrain.terrainData.heightmapResolution,
						terrains[0].terrain.terrainData.heightmapResolution
					});
				}
				if (grass_output)
				{
					grass_detail = new detail_class[terrains[0].terrain.terrainData.detailPrototypes.Length];
					for (int j = 0; j < grass_detail.Length; j++)
					{
						grass_detail[j] = new detail_class();
						grass_detail[j].detail = (int[,])System.Array.CreateInstance(typeof(int), new int[2]
						{
							(int)terrains[0].detail_resolution,
							(int)terrains[0].detail_resolution
						});
					}
					grass_resolution_old = (int)preterrain.detail_resolution;
				}
				generate_pause = false;
				prelayer_stack.Add(0);
				link_placed_reference();
				loop_prelayer("(gfc)(slv)(ocr)(asr)(cpo)(ias)(eho)(st)(cmn)(ed)", 0, loop_inactive: false);
				if (!find_terrain(first: true))
				{
					result = -1;
					break;
				}
				preterrain = terrains[prelayer.count_terrain];
				if (generate_world_mode)
				{
				}
				load_raw_heightmaps();
				if (!heightmap_output_layer)
				{
					heightmap_output = false;
				}
				if (prelayer.layer.Count == 0 && (!tree_output || !check_treemap()) && (!grass_output || !check_grassmap()))
				{
					result = -2;
					break;
				}
				if (prelayers.Count > 1)
				{
					area_stack_enabled = true;
				}
				generate_time_start = Time.realtimeSinceStartup;
				generate_time = 0f;
				tree_number = 0;
				auto_speed_time = Time.realtimeSinceStartup;
				generate_terrain_start();
				result = 1;
				break;
			}
		}
		return result;
	}

	public int GenerateHeightmapBegin()
	{
		only_heightmap = true;
		prelayer = prelayers[0];
		UnityEngine.Random.seed = seed;
		prelayer.count_terrain = 0;
		generate_world_mode = prelayers[0].prearea.active;
		generate_pause = false;
		prelayer_stack.Add(0);
		int result;
		if (!find_terrain(first: true))
		{
			result = -1;
		}
		else
		{
			preterrain = terrains[prelayer.count_terrain];
			load_raw_heightmaps();
			if (!heightmap_output_layer)
			{
				heightmap_output = false;
			}
			if (prelayers.Count > 1)
			{
				area_stack_enabled = true;
			}
			generate_time_start = Time.realtimeSinceStartup;
			generate_time = 0f;
			auto_speed_time = Time.realtimeSinceStartup;
			generate_terrain_start();
			result = 1;
		}
		return result;
	}

	public void select_automatic_step_resolution(terrain_class preterrain1, area_class prearea)
	{
		int num = 0;
		if (preterrain1.terrain.terrainData.heightmapResolution > num && heightmap_output)
		{
			num = preterrain1.terrain.terrainData.heightmapResolution;
			prearea.resolution_mode = resolution_mode_enum.Heightmap;
		}
		if (preterrain1.terrain.terrainData.alphamapResolution > num && color_output)
		{
			num = colormap_resolution;
			prearea.resolution_mode = resolution_mode_enum.Colormap;
		}
		if (preterrain1.terrain.terrainData.alphamapResolution > num && splat_output)
		{
			num = preterrain1.terrain.terrainData.alphamapResolution;
			prearea.resolution_mode = resolution_mode_enum.Splatmap;
		}
		if (preterrain1.terrain.terrainData.detailResolution > num && grass_output)
		{
			num = preterrain1.terrain.terrainData.detailResolution;
			prearea.resolution_mode = resolution_mode_enum.Detailmap;
		}
		if (prearea.tree_resolution > num && tree_output)
		{
			num = prearea.tree_resolution;
			prearea.resolution_mode = resolution_mode_enum.Tree;
		}
		if (prearea.object_resolution > num && object_output)
		{
			num = prearea.object_resolution;
			prearea.resolution_mode = resolution_mode_enum.Object;
		}
		if (num == 0)
		{
			num = 4;
			prearea.resolution_mode = resolution_mode_enum.Detailmap;
		}
	}

	public void select_automatic_step_resolution_mesh(area_class prearea)
	{
		resolution = object_resolution;
		prearea.resolution_mode = resolution_mode_enum.Object;
	}

	public void generate_mesh_start()
	{
		premesh = meshes[prelayer.count_terrain];
		Rect rect = get_mesh_area(prelayer.count_terrain);
		rect.xMin = Mathf.Ceil(rect.xMin / object_resolution) * object_resolution;
		rect.yMin = Mathf.Ceil(rect.yMin / object_resolution) * object_resolution;
		rect.xMax = Mathf.Floor(rect.xMax / object_resolution) * object_resolution;
		rect.yMax = Mathf.Floor(rect.yMax / object_resolution) * object_resolution;
		prelayer.prearea.area.xMin = rect.xMin;
		prelayer.prearea.area.yMin = rect.yMin;
		prelayer.prearea.area.width = rect.width;
		prelayer.prearea.area.height = rect.height;
		prelayer.y = prelayer.prearea.area.yMax;
	}

	public Rect get_mesh_area(int count_terrain)
	{
		Rect result = default(Rect);
		Vector3 center = meshes[count_terrain].mesh.bounds.center;
		float x = center.x;
		Vector3 extents = meshes[count_terrain].mesh.bounds.extents;
		float num = x - extents.x;
		Vector3 vector = meshes[count_terrain].gameObject.transform.position;
		result.xMin = num + vector.x;
		Vector3 center2 = meshes[count_terrain].mesh.bounds.center;
		float z = center2.z;
		Vector3 extents2 = meshes[count_terrain].mesh.bounds.extents;
		float num2 = z - extents2.z;
		Vector3 vector2 = meshes[count_terrain].gameObject.transform.position;
		result.yMin = num2 + vector2.z;
		Vector3 size = meshes[count_terrain].mesh.bounds.size;
		result.width = size.x;
		Vector3 size2 = meshes[count_terrain].mesh.bounds.size;
		result.height = size2.z;
		return result;
	}

	public void get_meshes_areas()
	{
		for (int i = 0; i < meshes.Count; i++)
		{
			meshes[i].area = get_mesh_area(i);
		}
	}

	public void calc_total_mesh_area()
	{
		Rect rect = default(Rect);
		meshes_area.area = get_mesh_area(0);
		for (int i = 1; i < meshes.Count; i++)
		{
			rect = get_mesh_area(i);
			if (!(rect.xMin >= meshes_area.area.xMin))
			{
				meshes_area.area.xMin = rect.xMin;
			}
			if (!(rect.xMax <= meshes_area.area.xMax))
			{
				meshes_area.area.xMax = rect.xMax;
			}
			if (!(rect.yMin >= meshes_area.area.yMin))
			{
				meshes_area.area.yMin = rect.yMin;
			}
			if (!(rect.yMax <= meshes_area.area.yMax))
			{
				meshes_area.area.yMax = rect.yMax;
			}
		}
	}

	public void GetMeshHeightSlope(mesh_class premesh1, Vector2 position)
	{
		Ray ray = default(Ray);
		ray.direction = new Vector3(0f, -1f, 0f);
		float x = position.x;
		Vector3 vector = premesh1.transform.position;
		ray.origin = new Vector3(x, vector.y + 1000f, position.y);
		RaycastHit hitInfo = default(RaycastHit);
		RaycastHit raycastHit = default(RaycastHit);
		if (Physics.Raycast(ray, out hitInfo, 2000f) && (hitInfo.collider.gameObject.layer & meshes_layer) == meshes_layer)
		{
			mesh_measure.hit = true;
			mesh_measure_class mesh_measure_class = mesh_measure;
			Vector3 point = hitInfo.point;
			mesh_measure_class.height = point.y;
			mesh_measure_class mesh_measure_class2 = mesh_measure;
			float num = 1f;
			Vector3 vector2 = hitInfo.normal;
			mesh_measure_class2.degree = num - (vector2.y - 0.5f) * 2f;
			mesh_measure.normal = hitInfo.normal;
			mesh_measure.transform = hitInfo.transform;
		}
		else
		{
			mesh_measure.hit = false;
		}
	}

	public void generate_terrain_start()
	{
		if (!generate_world_mode)
		{
			prelayer.prearea = preterrain.prearea;
			for (int i = 0; i < terrains.Count; i++)
			{
				terrains[i].on_row = false;
			}
			preterrain.on_row = true;
		}
		prelayer.y = prelayer.prearea.area.yMax;
		select_image_prelayer();
		if (button_export && heightmap_output)
		{
			export_bytes = new byte[(int)(Mathf.Pow(preterrain.terrain.terrainData.heightmapResolution, 2f) * 2f)];
		}
	}

	public int generate_output(prelayer_class prelayer3)
	{
		generate_error = true;
		int result;
		if (prelayer3.prearea.step.x == 0f || prelayer3.prearea.step.y == 0f)
		{
			generate = false;
			UnityEngine.Debug.Log("Area size is 0...");
			result = -1;
		}
		else
		{
			frames = 1f / (Time.realtimeSinceStartup - auto_speed_time);
			auto_speed_time = Time.realtimeSinceStartup;
			generate_speed = 10000;
			break_x = false;
			row_object_count = 0;
			prelayer3.counter_y = prelayer3.y;
			GameObject gameObject = default(GameObject);
			Color color = default(Color);
			int l = default(int);
			while (true)
			{
				object_class object_class;
				Quaternion quaternion;
				if (prelayer3.counter_y >= prelayer3.y - (float)generate_speed * prelayer.prearea.step.y)
				{
					generate_call_time = Time.realtimeSinceStartup;
					float y = prelayer3.y;
					int num = default(int);
					if (!(prelayer3.counter_y >= prelayer3.prearea.area.yMin))
					{
						if (prelayer_stack.Count > 1)
						{
							prelayer_stack.RemoveAt(prelayer_stack.Count - 1);
							prelayer = prelayers[prelayer_stack[prelayer_stack.Count - 1]];
							generate_error = false;
							result = 2;
							break;
						}
						if (generate_world_mode)
						{
							generate = false;
							for (num = 0; num < terrains.Count; num++)
							{
								terrain_apply(terrains[num]);
							}
						}
						else if (settings.showTerrains)
						{
							if (prelayer3.count_terrain >= terrains.Count - 1)
							{
								generate = false;
							}
							terrain_apply(terrains[prelayer3.count_terrain]);
						}
						else if (prelayer3.count_terrain >= meshes.Count - 1)
						{
							generate = false;
						}
						if (button_export)
						{
							export_name = export_file;
							if (terrains.Count > 1)
							{
								export_name += "_" + prelayer.count_terrain;
							}
							if ((settings.colormap || (bool)preterrain.rtp_script) && (settings.colormap_auto_assign || settings.normalmap_auto_assign))
							{
								script_base.preterrain = script_base.terrains[prelayer3.count_terrain];
							}
							generate_export = 1;
						}
						generate_time = Time.realtimeSinceStartup - generate_time_start;
						if (generate)
						{
							prelayer3.count_terrain++;
							if (settings.showTerrains)
							{
								if (find_terrain(first: false))
								{
									preterrain = terrains[prelayer3.count_terrain];
									generate_terrain_start();
								}
								else
								{
									generate = false;
								}
							}
							else if (find_mesh())
							{
								generate_mesh_start();
							}
							else
							{
								generate = false;
							}
						}
						else
						{
							object_apply();
						}
						generate_error = false;
						result = 2;
						break;
					}
					if (generate_world_mode || prelayer3.index > 0)
					{
						for (num = 0; num < terrains.Count; num++)
						{
							if (terrains[num].rect.Contains(new Vector2(terrains[num].prearea.area.x, y)))
							{
								terrains[num].on_row = true;
							}
							else
							{
								terrains[num].on_row = false;
							}
						}
					}
					prelayer3.x = prelayer3.prearea.area.x + prelayer3.break_x_value;
					for (; prelayer3.x <= prelayer3.prearea.area.xMax; prelayer3.x += prelayer3.prearea.step.x)
					{
						float x = prelayer3.x;
						float num2 = default(float);
						float num3 = default(float);
						float num4 = default(float);
						float num5 = prelayer3.counter_y;
						if (generate_world_mode || prelayer3.index > 0)
						{
							bool flag = true;
							for (num = 0; num < terrains.Count; num++)
							{
								if (terrains[num].rect.Contains(new Vector2(x, num5)))
								{
									flag = false;
									preterrain = terrains[num];
									break;
								}
							}
							if (flag)
							{
								continue;
							}
						}
						local_x = x - preterrain.rect.x;
						local_y = num5 - preterrain.rect.y;
						if (prelayer3.prearea.rotation_active)
						{
							Vector2 vector = calc_rotation_pixel(x, num5, prelayer3.prearea.center.x, prelayer3.prearea.center.y, prelayer3.prearea.rotation.y);
							x = vector.x;
							num5 = vector.y;
						}
						local_x_rot = x - preterrain.rect.x;
						local_y_rot = num5 - preterrain.rect.y;
						if (!only_heightmap)
						{
							if (settings.showTerrains)
							{
								degree = calc_terrain_angle(preterrain, local_x_rot, local_y_rot, settings.smooth_angle) * settings.global_degree_strength + settings.global_degree_level;
								height = preterrain.terrain.terrainData.GetHeight((int)(local_x_rot / preterrain.heightmap_conversion.x), (int)(local_y_rot / preterrain.heightmap_conversion.y)) / preterrain.size.y * settings.global_height_strength + settings.global_height_level;
								if (measure_normal)
								{
									normal = preterrain.terrain.terrainData.GetInterpolatedNormal(local_x_rot / preterrain.size.x, local_y_rot / preterrain.size.z);
								}
							}
							else
							{
								GetMeshHeightSlope(premesh, new Vector2(x, num5));
								if (!mesh_measure.hit)
								{
									continue;
								}
								degree = mesh_measure.degree * 90f;
								float num6 = mesh_measure.height;
								Vector3 vector2 = mesh_measure.transform.position;
								height = (num6 - vector2.y) / meshes_heightscale;
								normal = mesh_measure.normal;
							}
						}
						random_range = UnityEngine.Random.Range(0f, 1000f);
						if (!heightmap_output)
						{
							map_x = (int)Mathf.Round(local_x_rot / preterrain.splatmap_conversion.x);
							map_y = (int)Mathf.Round(local_y_rot / preterrain.splatmap_conversion.y);
							if (!((float)map_y <= preterrain.splatmap_resolution - 1f))
							{
								map_y = (int)(preterrain.splatmap_resolution - 1f);
							}
							else if (map_y < 0)
							{
								map_y = 0;
							}
							if (!((float)map_x <= preterrain.splatmap_resolution - 1f))
							{
								map_x = (int)(preterrain.splatmap_resolution - 1f);
							}
							else if (map_x < 0)
							{
								map_x = 0;
							}
						}
						if (grass_output)
						{
							detailmap_x = (int)Mathf.Floor(local_x_rot / preterrain.detailmap_conversion.x);
							detailmap_y = (int)Mathf.Floor(local_y_rot / preterrain.detailmap_conversion.y);
							if (!((float)detailmap_x <= preterrain.detail_resolution - 1f))
							{
								detailmap_x = (int)(preterrain.detail_resolution - 1f);
							}
							else if (detailmap_x < 0)
							{
								detailmap_x = 0;
							}
							if (!((float)detailmap_y <= preterrain.detail_resolution - 1f))
							{
								detailmap_y = (int)(preterrain.detail_resolution - 1f);
							}
							else if (detailmap_y < 0)
							{
								detailmap_y = 0;
							}
						}
						else if (heightmap_output)
						{
							heightmap_x = (int)Mathf.Round(local_x_rot / preterrain.heightmap_conversion.x);
							heightmap_y = (int)Mathf.Round(local_y_rot / preterrain.heightmap_conversion.y);
							heightmap_x_old = heightmap_x;
							heightmap_y_old = heightmap_y;
							if (!((float)heightmap_y <= preterrain.heightmap_resolution - 1f))
							{
								heightmap_y = (int)(preterrain.heightmap_resolution - 1f);
							}
							else if (heightmap_y < 0)
							{
								heightmap_y = 0;
							}
							if (!((float)heightmap_x <= preterrain.heightmap_resolution - 1f))
							{
								heightmap_x = (int)(preterrain.heightmap_resolution - 1f);
							}
							else if (heightmap_x < 0)
							{
								heightmap_x = 0;
							}
							heights[heightmap_y, heightmap_x] = 0f;
						}
						overlap = false;
						for (int i = 0; i < prelayer3.layer.Count; i++)
						{
							current_layer = prelayer3.layer[i];
							filter_value = 0f;
							filter_strength = 1f;
							if (current_layer.output == layer_output_enum.heightmap)
							{
								layer_x = (float)heightmap_x * preterrain.heightmap_conversion.x;
								layer_y = (float)heightmap_y * preterrain.heightmap_conversion.y;
							}
							else if (current_layer.output == layer_output_enum.color || current_layer.output == layer_output_enum.splat)
							{
								layer_x = (float)map_x * preterrain.splatmap_conversion.x;
								layer_y = (float)map_y * preterrain.splatmap_conversion.y;
							}
							else if (current_layer.output == layer_output_enum.grass)
							{
								layer_x = (float)detailmap_x * preterrain.detailmap_conversion.x;
								layer_y = (float)detailmap_y * preterrain.detailmap_conversion.y;
							}
							else
							{
								layer_x = local_x_rot;
								layer_y = local_y_rot;
							}
							for (int j = 0; j < current_layer.prefilter.filter_index.Count; j++)
							{
								calc_filter_value(filter[current_layer.prefilter.filter_index[j]], num5, x);
							}
							layer_output_enum output = current_layer.output;
							if (output == layer_output_enum.tree)
							{
								if (!overlap && !(subfilter_value * current_layer.strength <= 0f))
								{
									if (current_layer.tree_output.tree.Count == 0)
									{
										continue;
									}
									TreeInstance item = default(TreeInstance);
									float num7 = 0f;
									float num8 = default(float);
									float num9 = default(float);
									bool flag2 = true;
									int num10 = Mathf.FloorToInt(current_layer.tree_output.tree_value.curve.Evaluate(filter_value) * (float)current_layer.tree_output.tree.Count);
									if (num10 > current_layer.tree_output.tree.Count - 1)
									{
										num10 = current_layer.tree_output.tree.Count - 1;
									}
									if (num10 < 0)
									{
										num10 = 0;
									}
									tree_class tree_class = current_layer.tree_output.tree[num10];
									item.prototypeIndex = tree_class.prototypeindex;
									if (current_layer.positionSeed)
									{
										if (num5 == 0f || x == 0f)
										{
											UnityEngine.Random.seed = (int)((float)(seed - 10) + (num5 + 1f) * (x + 1f) + 1E+07f + (float)i);
										}
										else
										{
											UnityEngine.Random.seed = (int)((float)(seed - 10) + num5 * x + (float)i);
										}
									}
									random_range2 = UnityEngine.Random.value;
									if (!(random_range2 <= subfilter_value * current_layer.strength))
									{
										continue;
									}
									filter_value = 0f;
									for (int k = 0; k < tree_class.prefilter.filter_index.Count; k++)
									{
										calc_filter_value(filter[tree_class.prefilter.filter_index[k]], num5, x);
									}
									float num11 = tree_class.height_end - tree_class.height_start;
									float num12 = num11 * filter_value;
									float y2 = num12 + tree_class.height_start;
									float num13 = num12 / num11;
									float num14 = tree_class.width_end - tree_class.width_start;
									float num15 = num14 * num13 - tree_class.unlink * num12 + tree_class.width_start;
									if (!(num15 >= tree_class.width_start))
									{
										num15 = tree_class.width_start;
									}
									float num16 = num14 * num13 + tree_class.unlink * num12 + tree_class.width_start;
									if (!(num16 <= tree_class.width_end))
									{
										num16 = tree_class.width_end;
									}
									float num17 = UnityEngine.Random.Range(num15, num16);
									scale = new Vector3(num17, y2, num17);
									float num18 = 0f;
									float num19 = 0f;
									if (tree_class.random_position)
									{
										num18 = UnityEngine.Random.Range((0f - prelayer3.prearea.step.x) / 2f, prelayer.prearea.step.x / 2f);
										num19 = UnityEngine.Random.Range((0f - prelayer3.prearea.step.y) / 2f, prelayer.prearea.step.y / 2f);
									}
									float interpolatedHeight = preterrain.terrain.terrainData.GetInterpolatedHeight((local_x_rot + num18) / preterrain.size.x, (local_y_rot + num19) / preterrain.size.z);
									position = new Vector3(local_x_rot + num18, interpolatedHeight + tree_class.height, local_y_rot + num19);
									if (tree_class.distance_level != 0 || tree_class.min_distance.x != 0f || tree_class.min_distance.z != 0f || tree_class.min_distance.y != 0f)
									{
										object_info.position = position + new Vector3(preterrain.rect.x, 0f, preterrain.rect.y);
										object_info.min_distance = tree_class.min_distance;
										if (tree_class.distance_include_scale)
										{
											object_info.min_distance = new Vector3(object_info.min_distance.x * scale.x, object_info.min_distance.y * scale.y, object_info.min_distance.z * scale.z);
										}
										if (tree_class.distance_include_scale_group)
										{
											object_info.min_distance *= current_layer.tree_output.scale;
										}
										object_info.distance_rotation = tree_class.distance_rotation_mode;
										object_info.distance_mode = tree_class.distance_mode;
										switch (tree_class.distance_level)
										{
										case distance_level_enum.This:
											flag2 = check_object_distance(tree_class.objects_placed);
											break;
										case distance_level_enum.Layer:
											flag2 = check_object_distance(current_layer.objects_placed);
											break;
										case distance_level_enum.LayerLevel:
											flag2 = check_object_distance(prelayer3.objects_placed);
											break;
										case distance_level_enum.Global:
											flag2 = check_object_distance(objects_placed);
											break;
										}
									}
									if (tree_class.raycast)
									{
										if (tree_class.raycast_mode == raycast_mode_enum.Hit)
										{
											if (Physics.SphereCast(new Vector3(x + num18 + prelayer.prearea.step.x / 2f, height * preterrain.size.y + tree_class.cast_height, prelayer.counter_y + num19), tree_class.ray_radius, tree_class.ray_direction, out hit, tree_class.ray_length, tree_class.layerMask))
											{
												layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
												if ((layerHit & tree_class.layerMask) != 0)
												{
													continue;
												}
											}
										}
										else if (Physics.Raycast(new Vector3(x + num18 + prelayer.prearea.step.x / 2f, tree_class.cast_height, prelayer.counter_y + num19), tree_class.ray_direction, out hit, tree_class.ray_length, tree_class.layerMask))
										{
											layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
											if ((layerHit & tree_class.layerMask) != 0)
											{
												ref Vector3 reference = ref position;
												Vector3 point = hit.point;
												reference.y = point.y;
											}
										}
									}
									if (flag2)
									{
										item.position = new Vector3(position.x / preterrain.size.x, position.y / preterrain.size.y, position.z / preterrain.size.z);
										if (tree_class.precolor_range.color_range.Count != 0)
										{
											int num20 = Mathf.FloorToInt(tree_class.precolor_range.color_range_value.curve.Evaluate(subfilter_value) * (float)tree_class.precolor_range.color_range.Count);
											if (num20 > tree_class.precolor_range.color_range.Count - 1)
											{
												num20 = tree_class.precolor_range.color_range.Count - 1;
											}
											color_range_class color_range_class = tree_class.precolor_range.color_range[num20];
											tree_color = random_color_from_range(color_range_class.color_start, color_range_class.color_end);
										}
										item.color = tree_color;
										item.lightmapColor = tree_color;
										item.heightScale = scale.y * current_layer.tree_output.scale;
										item.widthScale = scale.x * current_layer.tree_output.scale;
										item.rotation = UnityEngine.Random.Range(0f, (float)Math.PI * 2f);
										tree_instances.Add(item);
										tree_class.placed++;
										prelayer.layer[i].tree_output.placed = prelayer.layer[i].tree_output.placed + 1;
										tree_class.placed_reference.placed = tree_class.placed;
										prelayer.layer[i].tree_output.placed_reference.placed = prelayer.layer[i].tree_output.placed;
										if (current_layer.nonOverlap)
										{
											overlap = true;
										}
									}
								}
							}
							else if (output == layer_output_enum.grass)
							{
								if (!(subfilter_value * current_layer.strength <= 0f))
								{
									int num21 = default(int);
									int num22 = 0;
									for (num21 = 0; num21 < preterrain.grass.Length; num21++)
									{
										num22 = (int)((float)num22 + preterrain.grass[num21]);
										grass_detail[num21].detail[detailmap_y, detailmap_x] = (int)((float)grass_detail[num21].detail[detailmap_y, detailmap_x] + preterrain.grass[num21] * settings.grass_density);
										if (grass_detail[num21].detail[detailmap_y, detailmap_x] < 0)
										{
											grass_detail[num21].detail[detailmap_y, detailmap_x] = 0;
										}
										else if (grass_detail[num21].detail[detailmap_y, detailmap_x] > 16)
										{
											grass_detail[num21].detail[detailmap_y, detailmap_x] = 16;
										}
									}
									if (current_layer.nonOverlap && num22 > 0)
									{
										overlap = true;
									}
								}
								for (count_value = 0; count_value < preterrain.grass.Length; count_value++)
								{
									preterrain.grass[count_value] = 0f;
								}
							}
							else if (output == layer_output_enum.@object)
							{
								if (!overlap && !(subfilter_value * current_layer.strength * filter_strength <= 0f))
								{
									if (current_layer.object_output.@object.Count == 0)
									{
										continue;
									}
									int num23 = (int)(current_layer.object_output.object_value.curve.Evaluate(filter_value) * (float)current_layer.object_output.@object.Count);
									if (num23 > current_layer.object_output.@object.Count - 1)
									{
										num23 = current_layer.object_output.@object.Count - 1;
									}
									if (num23 < 0)
									{
										num23 = 0;
									}
									object_class = current_layer.object_output.@object[num23];
									if (object_class.place_maximum && object_class.placed_prelayer >= object_class.place_max)
									{
										continue;
									}
									if (current_layer.positionSeed)
									{
										if (num5 == 0f || x == 0f)
										{
											UnityEngine.Random.seed = (int)((float)(seed - 10) + (num5 + 1f) * (x + 1f) + 1E+07f + (float)i);
										}
										else
										{
											UnityEngine.Random.seed = (int)((float)(seed - 10) + num5 * x + (float)i);
										}
									}
									random_range2 = UnityEngine.Random.Range(0f, 1f);
									if (!(random_range2 <= subfilter_value * current_layer.strength * filter_strength))
									{
										continue;
									}
									bool flag2 = true;
									bool flag3 = true;
									quaternion = Quaternion.identity;
									int num24 = default(int);
									position = new Vector3(x, 0f, num5);
									Vector3 position_start = object_class.position_start;
									Vector3 position_end = object_class.position_end;
									Vector3 vector3 = default(Vector3);
									vector3.x = UnityEngine.Random.Range(position_start.x, position_end.x);
									vector3.y = UnityEngine.Random.Range(position_start.y, position_end.y);
									vector3.z = UnityEngine.Random.Range(position_start.z, position_end.z);
									if (object_class.random_position)
									{
										vector3.x += UnityEngine.Random.Range(0f - prelayer3.prearea.step.x, prelayer3.prearea.step.x);
										vector3.z += UnityEngine.Random.Range(0f - prelayer3.prearea.step.y, prelayer3.prearea.step.y);
									}
									position += vector3;
									if (settings.showTerrains)
									{
										if (!preterrain.prearea.area.Contains(new Vector2(position.x, position.z)))
										{
											continue;
										}
									}
									else if (!premesh.area.Contains(new Vector2(position.x, position.z)))
									{
										continue;
									}
									if (object_class.terrain_rotate)
									{
										Vector3 interpolatedNormal = preterrain.terrain.terrainData.GetInterpolatedNormal((local_x_rot + vector3.x) / preterrain.size.x, (local_y_rot + vector3.y) / preterrain.size.z);
										interpolatedNormal.x = interpolatedNormal.x / 3f * 2f;
										interpolatedNormal.z = interpolatedNormal.z / 3f * 2f;
										quaternion = Quaternion.FromToRotation(Vector3.up, interpolatedNormal);
									}
									if (!object_class.rotation_map.active)
									{
										quaternion *= Quaternion.AngleAxis(UnityEngine.Random.Range(object_class.rotation_start.x, object_class.rotation_end.x), Vector3.right);
										quaternion *= Quaternion.AngleAxis(UnityEngine.Random.Range(object_class.rotation_start.y, object_class.rotation_end.y), Vector3.up);
										quaternion *= Quaternion.AngleAxis(UnityEngine.Random.Range(object_class.rotation_start.z, object_class.rotation_end.z), Vector3.forward);
										quaternion *= Quaternion.Euler(object_class.parent_rotation);
									}
									else
									{
										quaternion *= Quaternion.AngleAxis(object_class.rotation_map.calc_rotation(get_image_pixel(object_class.rotation_map.preimage, local_x, local_y)), Vector3.up);
									}
									if (object_class.look_at_parent)
									{
										Vector2 center = prelayer3.prearea.area.center;
										float x2 = center.x;
										float y3 = 0f;
										Vector2 center2 = prelayer3.prearea.area.center;
										Vector3 eulerAngles = Quaternion.LookRotation(new Vector3(x2, y3, center2.y) - position).eulerAngles;
										quaternion.y = eulerAngles.y;
									}
									if (object_class.rotation_steps)
									{
										Vector3 eulerAngles2 = quaternion.eulerAngles;
										if (object_class.rotation_step.x != 0f)
										{
											eulerAngles2.x = Mathf.Round(eulerAngles2.x / object_class.rotation_step.x) * object_class.rotation_step.x;
										}
										if (object_class.rotation_step.y != 0f)
										{
											eulerAngles2.y = Mathf.Round(eulerAngles2.y / object_class.rotation_step.y) * object_class.rotation_step.y;
										}
										if (object_class.rotation_step.z != 0f)
										{
											eulerAngles2.z = Mathf.Round(eulerAngles2.z / object_class.rotation_step.z) * object_class.rotation_step.z;
										}
										quaternion.eulerAngles = eulerAngles2;
									}
									if (current_layer.object_output.group_rotation)
									{
										int num25 = check_object_rotate(current_layer.object_output.objects_placed, current_layer.object_output.objects_placed_rot, position, (int)current_layer.object_output.min_distance_x_rot, (int)current_layer.object_output.min_distance_z_rot);
										if (num25 != -1)
										{
											quaternion.eulerAngles = current_layer.object_output.objects_placed_rot[num25];
											if (current_layer.object_output.group_rotation_steps)
											{
												if (current_layer.object_output.group_rotation_step.x != 0f)
												{
													quaternion.x += Mathf.Round(UnityEngine.Random.Range(0f, 360f / current_layer.object_output.group_rotation_step.x)) * current_layer.object_output.group_rotation_step.x;
												}
												if (current_layer.object_output.group_rotation_step.y != 0f)
												{
													quaternion.y += Mathf.Round(UnityEngine.Random.Range(0f, 360f / current_layer.object_output.group_rotation_step.y)) * current_layer.object_output.group_rotation_step.y;
												}
												if (current_layer.object_output.group_rotation_step.z != 0f)
												{
													quaternion.z += Mathf.Round(UnityEngine.Random.Range(0f, 360f / current_layer.object_output.group_rotation_step.z)) * current_layer.object_output.group_rotation_step.z;
												}
											}
										}
									}
									if (object_class.terrain_height)
									{
										if (settings.showTerrains)
										{
											height_interpolated = preterrain.terrain.terrainData.GetInterpolatedHeight((local_x_rot + vector3.x) / preterrain.size.x, (local_y_rot + vector3.z) / preterrain.size.z);
											ref Vector3 reference2 = ref position;
											float num26 = height_interpolated;
											Vector3 vector4 = preterrain.terrain.transform.position;
											reference2.y = num26 + vector4.y + vector3.y;
										}
										else
										{
											GetMeshHeightSlope(premesh, new Vector2(x + vector3.x, num5 + vector3.z));
											if (!mesh_measure.hit)
											{
												continue;
											}
											height_interpolated = mesh_measure.height;
											degree = mesh_measure.degree;
											position.y = height_interpolated + vector3.y;
										}
									}
									if (!(object_class.sphereOverlapRadius <= 0f) && Physics.OverlapSphere(new Vector3(position.x, position.y + object_class.sphereOverlapHeight, position.z), object_class.sphereOverlapRadius).Length != 0)
									{
										continue;
									}
									position.y -= degree * object_class.slopeY;
									float num27 = object_class.scale_end.x - object_class.scale_start.x;
									scale.x = UnityEngine.Random.Range(object_class.scale_start.x, object_class.scale_end.x);
									float num28 = scale.x - object_class.scale_start.x;
									float num29 = num28 / num27;
									float num30 = object_class.scale_end.y - object_class.scale_start.y;
									float num31 = num30 * num29 - object_class.unlink_y * num28 + object_class.scale_start.y;
									if (!(num31 >= object_class.scale_start.y))
									{
										num31 = object_class.scale_start.y;
									}
									float num32 = num30 * num29 + object_class.unlink_y * num28 + object_class.scale_start.y;
									if (!(num32 <= object_class.scale_end.y))
									{
										num32 = object_class.scale_end.y;
									}
									scale.y = UnityEngine.Random.Range(num31, num32);
									float num33 = object_class.scale_end.z - object_class.scale_start.z;
									float num34 = num33 * num29 - object_class.unlink_z * num28 + object_class.scale_start.z;
									if (!(num34 >= object_class.scale_start.z))
									{
										num34 = object_class.scale_start.z;
									}
									float num35 = num33 * num29 + object_class.unlink_z * num28 + object_class.scale_start.z;
									if (!(num35 <= object_class.scale_end.z))
									{
										num35 = object_class.scale_end.z;
									}
									scale.z = UnityEngine.Random.Range(num34, num35);
									if (object_class.raycast)
									{
										if (object_class.raycast_mode == raycast_mode_enum.Hit)
										{
											if (Physics.SphereCast(new Vector3(x + prelayer.prearea.step.x / 2f, height * preterrain.size.y + object_class.cast_height, prelayer.counter_y), object_class.ray_radius, object_class.ray_direction, out hit, object_class.ray_length, object_class.layerMask))
											{
												layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
												if ((layerHit & object_class.layerMask) != 0)
												{
													continue;
												}
											}
										}
										else if (Physics.Raycast(new Vector3(x + prelayer.prearea.step.x / 2f, object_class.cast_height, prelayer.counter_y), object_class.ray_direction, out hit, object_class.ray_length, object_class.layerMask))
										{
											layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
											if ((layerHit & object_class.layerMask) != 0)
											{
												ref Vector3 reference3 = ref position;
												Vector3 point2 = hit.point;
												reference3.y = point2.y;
											}
										}
									}
									if (object_class.pivot_center)
									{
										position.y += scale.y / 2f;
									}
									bool flag4 = false;
									if (object_class.distance_level != 0 || object_class.min_distance.x != 0f || object_class.min_distance.z != 0f || object_class.min_distance.y != 0f)
									{
										flag4 = true;
										object_info.position = position;
										object_info.rotation = quaternion.eulerAngles;
										object_info.min_distance = object_class.min_distance;
										if (object_class.distance_include_scale)
										{
											object_info.min_distance = new Vector3(object_info.min_distance.x * scale.x, object_info.min_distance.y * scale.y, object_info.min_distance.z * scale.z);
										}
										if (object_class.distance_include_scale_group)
										{
											object_info.min_distance *= current_layer.object_output.scale;
										}
										if (object_class.includeScale)
										{
											object_info.min_distance = Vector3.Scale(object_info.min_distance, object_class.object1.transform.lossyScale);
										}
										object_info.distance_rotation = object_class.distance_rotation_mode;
										object_info.distance_mode = object_class.distance_mode;
										switch (object_class.distance_level)
										{
										case distance_level_enum.This:
											flag2 = check_object_distance(object_class.objects_placed);
											break;
										case distance_level_enum.Layer:
											flag2 = check_object_distance(current_layer.objects_placed);
											break;
										case distance_level_enum.LayerLevel:
											flag2 = check_object_distance(prelayer3.objects_placed);
											break;
										case distance_level_enum.Global:
											flag2 = check_object_distance(objects_placed);
											break;
										}
									}
									scale *= current_layer.object_output.scale;
									if (object_class.includeScale)
									{
										scale = Vector3.Scale(scale, object_class.object1.transform.localScale);
									}
									if (flag2)
									{
										float z = preterrain.size.z;
										z /= preterrain.heightmap_resolution;
										if (current_layer.nonOverlap)
										{
											overlap = true;
										}
										if (!object_class.objectStream)
										{
											gameObject = null;
											gameObject = (GameObject)UnityEngine.Object.Instantiate(object_class.object1, position, Quaternion.identity);
											pointsRange.Add(new object_point_class(new Vector2(position.x, position.z), gameObject));
											if (object_class.lookAtObject != null)
											{
												gameObject.transform.LookAt(object_class.lookAtObject);
												Transform transform = gameObject.transform;
												Vector3 eulerAngles3 = quaternion.eulerAngles;
												float x3 = eulerAngles3.x;
												Vector3 eulerAngles4 = gameObject.transform.eulerAngles;
												float y4 = eulerAngles4.y;
												Vector3 eulerAngles5 = quaternion.eulerAngles;
												float y5 = y4 + eulerAngles5.y;
												Vector3 eulerAngles6 = quaternion.eulerAngles;
												transform.eulerAngles = new Vector3(x3, y5, eulerAngles6.z);
											}
											else
											{
												gameObject.transform.rotation = quaternion;
											}
											gameObject.transform.localScale = scale;
											gameObject.SetActive(value: false);
											placedObjects.Add(gameObject);
											int num36 = 0;
											if (object_class.object_material.active)
											{
												num36 = object_class.object_material.set_material(gameObject, 0);
											}
											if (object_class.combine)
											{
												if (object_class.object_material.combine_count[num36] >= object_class.mesh_combine || (!object_class.combine_total && object_class.placed_prelayer == 0))
												{
													object_class.object_material.combine_count[num36] = 0;
												}
												if (object_class.object_material.combine_count[num36] == 0)
												{
													string rhs = null;
													if (object_class.object_material.material.Count > 1)
													{
														rhs = "_mat" + num36;
													}
													object_class.object_material.combine_parent[num36] = UnityEngine.Object.Instantiate(Combine_Children);
													if (settings.parentObjectsTerrain)
													{
														object_class.object_material.combine_parent[num36].transform.parent = preterrain.objectParent.transform;
													}
													else
													{
														object_class.object_material.combine_parent[num36].transform.parent = object_class.parent;
													}
													if (object_class.combine_parent_name == string.Empty)
													{
														object_class.object_material.combine_parent[num36].name = object_class.object1.name + rhs;
													}
													else
													{
														object_class.object_material.combine_parent[num36].name = object_class.combine_parent_name + rhs;
													}
												}
												gameObject.transform.parent = object_class.object_material.combine_parent[num36].transform;
											}
											else if (settings.parentObjectsTerrain)
											{
												gameObject.transform.parent = preterrain.objectParent.transform;
											}
											else
											{
												gameObject.transform.parent = object_class.parent;
											}
											object_class.object_material.combine_count[num36] = object_class.object_material.combine_count[num36] + 1;
											gameObject.name = object_class.object1.name + "_" + object_class.placed;
										}
										if (flag4)
										{
											current_layer.object_output.objects_placed.Add(position);
											if (current_layer.object_output.group_rotation)
											{
												current_layer.object_output.objects_placed_rot.Add(quaternion.eulerAngles);
											}
										}
										object_class.placed++;
										object_class.placed_prelayer++;
										current_layer.object_output.placed = current_layer.object_output.placed + 1;
										row_object_count++;
										object_class.placed_reference.placed = object_class.placed;
										current_layer.object_output.placed_reference.placed = current_layer.object_output.placed;
										object_class.object2 = gameObject;
										if (object_class.prelayer_created && prelayers[object_class.prelayer_index].prearea.active)
										{
											goto IL_2b03;
										}
									}
								}
							}
							else if (output == layer_output_enum.heightmap && !button_export)
							{
								heights[heightmap_y, heightmap_x] += filter_value * current_layer.strength;
							}
							if (current_layer.output == layer_output_enum.splat)
							{
								for (count_value = 0; count_value < preterrain.splat_length; count_value++)
								{
									preterrain.splat_layer[count_value] = preterrain.splat_layer[count_value] + preterrain.splat[count_value];
								}
								for (count_value = 0; count_value < Extensions.get_length((System.Array)preterrain.splat); count_value++)
								{
									preterrain.splat[count_value] = 0f;
								}
							}
							if (current_layer.output == layer_output_enum.color)
							{
								for (count_value = 0; count_value < preterrain.color_length; count_value++)
								{
									preterrain.color_layer[count_value] = preterrain.color_layer[count_value] + preterrain.color[count_value];
								}
								for (count_value = 0; count_value < preterrain.color_length; count_value++)
								{
									preterrain.color[count_value] = 0f;
								}
							}
						}
						if (button_export)
						{
							color = default(Color);
							if (color_output)
							{
								for (count_value = 0; count_value < 3; count_value++)
								{
									color[count_value] = preterrain.color_layer[count_value];
									preterrain.color_layer[count_value] = 0f;
								}
							}
							if (splat_output)
							{
								for (count_value = 0; count_value < 3; count_value++)
								{
									color[count_value] = preterrain.splat_layer[count_value];
									preterrain.splat_layer[count_value] = 0f;
								}
							}
							if (heightmap_output)
							{
								convert_16to8_bit(heights[heightmap_y, heightmap_x]);
								color[0] = 0f;
								color[1] = (float)byte_hi * 1f / 255f;
								color[2] = (float)byte_lo * 1f / 255f;
								color[3] = 0f;
								export_bytes[heightmap_x * 2 + heightmap_y * 2049 * 2] = (byte)byte_hi;
								export_bytes[heightmap_x * 2 + 1 + heightmap_y * 2049 * 2] = (byte)byte_lo;
							}
							export_texture.SetPixel(map_x, map_y, color);
						}
						else
						{
							if (splat_output)
							{
								float num37 = default(float);
								int num38 = preterrain.splat_layer.Length / 4;
								num37 = 0f;
								for (count_value = 0; count_value < preterrain.splat_layer.Length; count_value++)
								{
									num37 += preterrain.splat_layer[count_value];
								}
								for (l = 0; l < num38; l++)
								{
									for (count_value = 0; count_value < 4; count_value++)
									{
										color[count_value] = preterrain.splat_layer[l * 4 + count_value] / num37;
										preterrain.splat_layer[l * 4 + count_value] = 0f;
									}
									preterrain.splat_alpha[l].SetPixel(map_x, map_y, color);
								}
							}
							if (color_output)
							{
								if (!settings.direct_colormap)
								{
									color[3] = 0f;
									for (count_value = 0; count_value < 3; count_value++)
									{
										color[count_value] = preterrain.color_layer[count_value];
										preterrain.color_layer[count_value] = 0f;
									}
									preterrain.splat_alpha[l].SetPixel(map_x, map_y, color);
								}
								else
								{
									color[3] = 1f;
									for (count_value = 0; count_value < 3; count_value++)
									{
										color[count_value] = preterrain.color_layer[count_value];
										preterrain.color_layer[count_value] = 0f;
									}
									preterrain.ColorGlobal.SetPixel(map_x, map_y, color);
								}
							}
						}
						if (Time.realtimeSinceStartup - auto_speed_time <= 1f / (float)target_frame)
						{
							continue;
						}
						goto IL_33ce;
					}
					prelayer3.break_x_value = 0f;
					prelayer3.counter_y -= prelayer.prearea.step.y;
					continue;
				}
				prelayer3.y -= (float)(generate_speed + 1) * prelayer.prearea.step.y;
				generate_time = Time.realtimeSinceStartup - generate_time_start;
				generate_error = false;
				result = 1;
				break;
				IL_33ce:
				prelayer3.break_x_value = prelayer3.x - prelayer3.prearea.area.x + prelayer3.prearea.step.x;
				row_object_count = 0;
				break_x = true;
				prelayer3.y = prelayer3.counter_y;
				generate_time = Time.realtimeSinceStartup - generate_time_start;
				generate_error = false;
				result = 4;
				break;
				IL_2b03:
				set_object_child(object_class, quaternion.eulerAngles);
				prelayer3.x += prelayer3.prearea.step.x;
				prelayer3.y = prelayer3.counter_y;
				if (!(prelayer3.x > prelayer.prearea.area.xMax))
				{
					prelayer3.break_x_value = prelayer3.x - prelayer3.prearea.area.x;
				}
				else
				{
					prelayer3.y -= prelayer3.prearea.step.y;
					prelayer3.break_x_value = 0f;
				}
				prelayer_stack.Add(object_class.prelayer_index);
				prelayer = prelayers[object_class.prelayer_index];
				prelayer.prearea.area.x = position.x + prelayer.prearea.area_old.x * scale.x;
				prelayer.prearea.area.y = position.z + prelayer.prearea.area_old.y * scale.z;
				prelayer.prearea.area.width = prelayer.prearea.area_old.width * scale.x;
				prelayer.prearea.area.height = prelayer.prearea.area_old.height * scale.z;
				if (quaternion.y != 0f)
				{
					prelayer.prearea.rotation = quaternion.eulerAngles;
					prelayer.prearea.rotation_active = true;
				}
				prelayer.prearea.step.y = Mathf.Sqrt(Mathf.Pow(prelayer.prearea.step_old.x, 2f) + Mathf.Pow(prelayer.prearea.step_old.y, 2f)) / 2f;
				prelayer.prearea.step.x = prelayer.prearea.step.y;
				prelayer.prearea.center = new Vector2(position.x, position.z);
				prelayer.y = prelayer.prearea.area.yMax;
				generate_error = false;
				result = 3;
				break;
			}
		}
		return result;
	}

	public void set_object_child(object_class @object, Vector3 rotation)
	{
		for (int i = 0; i < @object.object_child.Count; i++)
		{
			@object.object_child[i].parent_rotation = rotation;
			if (!@object.object_child[i].place_maximum_total)
			{
				@object.object_child[i].placed_prelayer = 0;
			}
			if (!@object.object_child[i].parent || @object.object_child[i].parent_set)
			{
				@object.object_child[i].parent = @object.object2.transform;
				@object.object_child[i].parent_set = true;
			}
		}
	}

	public void create_object_child_list(object_class @object)
	{
		if (!@object.prelayer_created)
		{
			return;
		}
		for (int i = 0; i < prelayers[@object.prelayer_index].layer.Count; i++)
		{
			if (prelayers[@object.prelayer_index].layer[i].output == layer_output_enum.@object)
			{
				for (int j = 0; j < prelayers[@object.prelayer_index].layer[i].object_output.@object.Count; j++)
				{
					@object.object_child.Add(prelayers[@object.prelayer_index].layer[i].object_output.@object[j]);
				}
			}
		}
	}

	public void calc_filter_value(filter_class filter, float counter_y, float x)
	{
		float num = default(float);
		float num2 = default(float);
		Color color = default(Color);
		Color color2 = default(Color);
		filter_input = 0f;
		filter_strength = filter.strength;
		bool flag = false;
		if (filter.device == filter_devices_enum.Standard)
		{
			switch (filter.type)
			{
			case condition_type_enum.Height:
				filter_input = height;
				break;
			case condition_type_enum.Current:
				if (filter.change_mode == change_mode_enum.filter)
				{
					filter_input = filter_value;
				}
				else if (current_layer.output == layer_output_enum.heightmap)
				{
					filter_input = filter_value + heights[heightmap_y, heightmap_x];
				}
				break;
			case condition_type_enum.Always:
				filter_input = filter.curve_position;
				break;
			case condition_type_enum.Steepness:
				filter_input = degree / 90f;
				break;
			case condition_type_enum.Direction:
			{
				float num3 = default(float);
				float num4 = default(float);
				float num5 = default(float);
				num3 = ((normal.x < 0f) ? filter.precurve_x_left.curve.Evaluate(normal.x) : filter.precurve_x_right.curve.Evaluate(normal.x));
				num5 = ((normal.z < 0f) ? filter.precurve_z_left.curve.Evaluate(normal.z) : filter.precurve_z_right.curve.Evaluate(normal.z));
				num4 = filter.precurve_y.curve.Evaluate(normal.y);
				float num6 = filter_input = num3 + num4 + num5;
				break;
			}
			case condition_type_enum.Image:
				color2 = calc_image_value(filter.preimage, layer_x, layer_y);
				if (filter.preimage.splatmap)
				{
					flag = true;
					if (!filter.preimage.includeAlpha)
					{
						color2.a = 0f;
					}
				}
				if (filter.preimage.output)
				{
					filter_input = filter.preimage.output_pos;
				}
				break;
			case condition_type_enum.RawHeightmap:
				calc_raw_value(filter.raw, layer_x, layer_y);
				filter_input = filter.raw.output_pos;
				break;
			case condition_type_enum.Random:
				filter_input = UnityEngine.Random.Range(0f, 1f);
				break;
			case condition_type_enum.RandomRange:
				if (!(random_range <= filter.range_start) && !(random_range >= filter.range_end))
				{
					filter_input = UnityEngine.Random.Range(0f, 1f);
				}
				break;
			case condition_type_enum.Splatmap:
				if (splat_output)
				{
					filter_input = preterrain.splat_layer[filter.splat_index];
					if (!(filter_input >= filter.curve_position))
					{
						filter_input = 0f;
					}
				}
				else if (filter.splatmap < preterrain.splat_alpha.Length)
				{
					this.color = preterrain.splat_alpha[filter.splatmap].GetPixel(map_x, map_y);
					filter_input = this.color[filter.splat_index - filter.splatmap * 4];
					if (!(filter_input >= filter.curve_position))
					{
						filter_input = 0f;
					}
				}
				else
				{
					filter_input = 1f;
				}
				break;
			case condition_type_enum.RayCast:
				if (filter.raycast_mode == raycast_mode_enum.Hit)
				{
					if (Physics.SphereCast(new Vector3(x + prelayer.prearea.step.x / 2f, height * preterrain.size.y + filter.cast_height, prelayer.counter_y), prelayer.prearea.step.x / 2f * filter.ray_radius, filter.ray_direction, out hit, filter.ray_length, filter.layerMask))
					{
						layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
						if ((layerHit & filter.layerMask) != 0)
						{
							filter_input = 0f;
						}
						else
						{
							filter_input = 1f;
						}
					}
					else
					{
						filter_input = 1f;
					}
				}
				else
				{
					if (filter.raycast_mode != raycast_mode_enum.Height)
					{
						break;
					}
					if (Physics.Raycast(new Vector3(x + prelayer.prearea.step.x / 2f, filter.cast_height, prelayer.counter_y), filter.ray_direction, out hit, filter.ray_length, filter.layerMask))
					{
						layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
						if ((layerHit & filter.layerMask) != 0)
						{
							Vector3 point = hit.point;
							float y = point.y;
							Vector3 size = preterrain.terrain.terrainData.size;
							filter_input = y / size.y;
						}
						else
						{
							filter_strength = 0f;
						}
					}
					else
					{
						filter_strength = 0f;
					}
				}
				break;
			}
		}
		else if (filter.device == filter_devices_enum.Math)
		{
			device2_type_enum type = filter.type2;
			if (type == device2_type_enum.Sin)
			{
				filter_input = Mathf.Sin(x * 1f / 20f);
			}
			else if (type == device2_type_enum.Sin)
			{
				filter_input = Mathf.Cos(x * 1f / 20f);
			}
		}
		for (int i = 0; i < filter.precurve_list.Count; i++)
		{
			switch (filter.precurve_list[i].type)
			{
			case curve_type_enum.Normal:
				filter_input = filter.precurve_list[i].curve.Evaluate(filter_input);
				break;
			case curve_type_enum.Random:
				num = filter.precurve_list[i].curve.Evaluate(filter_input);
				if (!filter.precurve_list[i].abs)
				{
					filter_input += UnityEngine.Random.Range(0f - num, num);
				}
				else
				{
					filter_input += UnityEngine.Random.Range(0f, num);
				}
				break;
			case curve_type_enum.Perlin:
			{
				Vector2 vector = default(Vector2);
				vector = ((!filter.precurve_list[i].rotation) ? new Vector2(x, counter_y) : calc_rotation_pixel(x, counter_y, 0f, 0f, 0f - filter.precurve_list[i].rotation_value));
				num2 = filter.precurve_list[i].curve.Evaluate(filter_input);
				num = perlin_noise(vector.x, vector.y, filter.precurve_list[i].offset.x, filter.precurve_list[i].offset.y, filter.precurve_list[i].frequency, filter.precurve_list[i].detail, filter.precurve_list[i].detail_strength) * num2 * filter.precurve_list[i].strength;
				if (!filter.precurve_list[i].abs)
				{
					filter_input += num * 2f - num2;
				}
				else
				{
					filter_input += num;
				}
				break;
			}
			}
		}
		if (filter.presubfilter.subfilter_index.Count > 0)
		{
			if (filter.sub_strength_set)
			{
				subfilter_value = 0f;
			}
			else
			{
				subfilter_value = 1f;
			}
			for (int j = 0; j < filter.presubfilter.subfilter_index.Count; j++)
			{
				current_subfilter = subfilter[filter.presubfilter.subfilter_index[j]];
				calc_subfilter_value(filter, current_subfilter, counter_y, x);
			}
			if (filter.last_value_declared)
			{
				int num7 = (int)((x - prelayer.prearea.area.xMin) / prelayer.prearea.step.x);
				filter.last_value_y[num7] = filter_input;
				filter.last_pos_x = num7;
				filter.last_value_x[0] = filter_input;
			}
		}
		else
		{
			subfilter_value = 1f;
		}
		float num8 = 0f;
		if (!filter.combine)
		{
			filter_input += filter_combine;
			filter_combine = 0f;
			filter_combine_start = 0f;
		}
		else if (filter_combine_start != 0f)
		{
			filter_combine_start = filter_value;
		}
		if (current_layer.output == layer_output_enum.splat && (filter.type != condition_type_enum.Image || !filter.preimage.edge_blur))
		{
			for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
			{
				preterrain.splat_calc[count_value] = 0f;
			}
			for (count_value = 0; count_value < current_layer.splat_output.splat.Count; count_value++)
			{
				if (current_layer.splat_output.splat_custom[count_value].custom)
				{
					for (int k = 0; k < preterrain.splat.Length; k++)
					{
						preterrain.splat_calc[k] = preterrain.splat_calc[k] + current_layer.splat_output.curves[count_value].curve.Evaluate(current_layer.splat_output.splat_value.curve.Evaluate(filter_input)) * (current_layer.splat_output.splat_custom[count_value].value[k] / current_layer.splat_output.splat_custom[count_value].totalValue);
					}
				}
				else
				{
					int num9 = current_layer.splat_output.splat[count_value];
					preterrain.splat_calc[num9] = preterrain.splat_calc[num9] + current_layer.splat_output.curves[count_value].curve.Evaluate(current_layer.splat_output.splat_value.curve.Evaluate(filter_input));
				}
			}
		}
		if (current_layer.output == layer_output_enum.color)
		{
			if (filter.type == condition_type_enum.Image && filter.preimage.rgb)
			{
				color = color2;
			}
			else
			{
				color[0] = current_layer.color_output.precolor_range[filter.color_output_index].curve_red.Evaluate(current_layer.color_output.precolor_range[filter.color_output_index].color_range_value.curve.Evaluate(filter_input));
				color[1] = current_layer.color_output.precolor_range[filter.color_output_index].curve_green.Evaluate(current_layer.color_output.precolor_range[filter.color_output_index].color_range_value.curve.Evaluate(filter_input));
				color[2] = current_layer.color_output.precolor_range[filter.color_output_index].curve_blue.Evaluate(current_layer.color_output.precolor_range[filter.color_output_index].color_range_value.curve.Evaluate(filter_input));
				color[3] = 0f;
			}
			if (export_color_advanced)
			{
				color *= export_color;
				if (export_color_curve_advanced)
				{
					color[0] = export_color_curve_red.Evaluate(color[0]);
					color[1] = export_color_curve_green.Evaluate(color[1]);
					color[2] = export_color_curve_blue.Evaluate(color[2]);
				}
				else
				{
					color[0] = export_color_curve.Evaluate(color[0]);
					color[1] = export_color_curve.Evaluate(color[1]);
					color[2] = export_color_curve.Evaluate(color[2]);
				}
			}
		}
		else if (current_layer.output == layer_output_enum.grass)
		{
			for (count_value = 0; count_value < current_layer.grass_output.grass_calc.Count; count_value++)
			{
				current_layer.grass_output.grass_calc[count_value] = current_layer.grass_output.curves[count_value].curve.Evaluate(current_layer.grass_output.grass_value.curve.Evaluate(filter_input));
			}
		}
		switch (filter.output)
		{
		case condition_output_enum.add:
			if (current_layer.output == layer_output_enum.heightmap)
			{
				filter_value += filter_input * filter_strength * subfilter_value;
			}
			else
			{
				filter_value += filter_input;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < 3; count_value++)
				{
					preterrain.color[count_value] = preterrain.color[count_value] + color[count_value] * (current_layer.strength * filter_strength * subfilter_value);
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat[count_value] + preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value);
					}
					break;
				}
				count_value = 0;
				while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
				{
					int num12 = current_layer.splat_output.splat[count_value];
					preterrain.splat[num12] = preterrain.splat[num12] + color2[count_value] * (current_layer.strength * filter_strength * subfilter_value);
					count_value++;
				}
			}
			else if (current_layer.output == layer_output_enum.grass)
			{
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] = preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] + current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value);
				}
			}
			break;
		case condition_output_enum.subtract:
			if (current_layer.output == layer_output_enum.heightmap)
			{
				filter_value -= filter_input * filter_strength * subfilter_value;
			}
			else
			{
				filter_value -= filter_input;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < 3; count_value++)
				{
					preterrain.color[count_value] = preterrain.color[count_value] - color[count_value] * (current_layer.strength * filter_strength * subfilter_value);
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat[count_value] - preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value);
					}
					break;
				}
				count_value = 0;
				while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
				{
					int num14 = current_layer.splat_output.splat[count_value];
					preterrain.splat[num14] = preterrain.splat[num14] - color2[count_value] * (current_layer.strength * filter_strength * subfilter_value);
					count_value++;
				}
			}
			else if (current_layer.output == layer_output_enum.grass)
			{
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] = preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] - current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value);
				}
			}
			break;
		case condition_output_enum.change:
			if (current_layer.output == layer_output_enum.heightmap)
			{
				if (filter.change_mode == change_mode_enum.filter)
				{
					filter_value = filter_value * (1f - subfilter_value * filter_strength) + filter_input * (subfilter_value * filter_strength);
				}
				else
				{
					if (filter.combine)
					{
						filter_combine = filter_value - filter_combine_start;
						break;
					}
					heights[heightmap_y, heightmap_x] = (heights[heightmap_y, heightmap_x] + filter_value) * (1f - subfilter_value * filter_strength) + filter_input * (subfilter_value * filter_strength);
				}
			}
			else
			{
				filter_value = filter_value * (1f - subfilter_value) + filter_input * subfilter_value;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				if (filter.type == condition_type_enum.Current)
				{
					if (filter.change_mode == change_mode_enum.filter)
					{
						for (count_value = 0; count_value < 3; count_value++)
						{
							preterrain.color[count_value] = preterrain.color[count_value] - preterrain.color[count_value] * (1f - subfilter_value) * current_layer.strength * filter_strength;
						}
					}
					else
					{
						for (count_value = 0; count_value < 3; count_value++)
						{
							preterrain.color_layer[count_value] = preterrain.color_layer[count_value] - preterrain.color_layer[count_value] * (1f - subfilter_value) * current_layer.strength * filter_strength;
						}
					}
				}
				else
				{
					for (count_value = 0; count_value < 3; count_value++)
					{
						preterrain.color_layer[count_value] = preterrain.color_layer[count_value] * (1f - subfilter_value * filter_strength * current_layer.strength) + color[count_value] * subfilter_value * filter_strength * current_layer.strength;
					}
				}
			}
			if (current_layer.output != layer_output_enum.splat)
			{
				break;
			}
			if (filter.type == condition_type_enum.Current)
			{
				if (filter.change_mode == change_mode_enum.filter)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat[count_value] - preterrain.splat[count_value] * (1f - subfilter_value) * current_layer.strength * filter_strength;
					}
				}
				else
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat_layer[count_value] = preterrain.splat_layer[count_value] - preterrain.splat_layer[count_value] * (1f - subfilter_value) * current_layer.strength * filter_strength;
					}
				}
				break;
			}
			if (filter.change_mode == change_mode_enum.filter)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat[count_value] * (1f - filter_strength * current_layer.strength * subfilter_value) + preterrain.splat_calc[count_value] * subfilter_value * filter_strength * current_layer.strength;
					}
				}
				else
				{
					count_value = 0;
					while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
					{
						preterrain.splat[current_layer.splat_output.splat[count_value]] = preterrain.splat[current_layer.splat_output.splat[count_value]] * (1f - filter_strength * current_layer.strength * subfilter_value) + color2[count_value] * (current_layer.strength * filter_strength * subfilter_value);
						count_value++;
					}
				}
				break;
			}
			for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
			{
				preterrain.splat_layer[count_value] = preterrain.splat_layer[count_value] * (1f - filter_strength * current_layer.strength * subfilter_value);
			}
			if (!flag)
			{
				for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
				{
					preterrain.splat[count_value] = preterrain.splat[count_value] + preterrain.splat_calc[count_value] * subfilter_value * filter_strength * current_layer.strength;
				}
				break;
			}
			count_value = 0;
			while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
			{
				int num16 = current_layer.splat_output.splat[count_value];
				preterrain.splat[num16] = preterrain.splat[num16] + color2[count_value] * (current_layer.strength * filter_strength * subfilter_value);
				count_value++;
			}
			break;
		case condition_output_enum.multiply:
			if (current_layer.output == layer_output_enum.heightmap)
			{
				filter_value *= filter_input * filter_strength * subfilter_value;
			}
			else
			{
				filter_value *= filter_input;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < current_layer.splat_output.splat.Count; count_value++)
				{
					preterrain.color[count_value] = preterrain.color[count_value] * (color[count_value] * (current_layer.strength * filter_strength * subfilter_value));
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat[count_value] * (preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value));
					}
					break;
				}
				count_value = 0;
				while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
				{
					int num11 = current_layer.splat_output.splat[count_value];
					preterrain.splat[num11] = preterrain.splat[num11] * (color2[count_value] * (current_layer.strength * filter_strength * subfilter_value));
					count_value++;
				}
			}
			else if (current_layer.output == layer_output_enum.grass)
			{
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] = preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] * (current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value));
				}
			}
			break;
		case condition_output_enum.divide:
			if (current_layer.output == layer_output_enum.heightmap)
			{
				if (filter_input * filter_strength * subfilter_value != 0f)
				{
					filter_value /= filter_input * filter_strength * subfilter_value;
				}
			}
			else if (filter_input != 0f)
			{
				filter_value /= filter_input;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < 3; count_value++)
				{
					if (color[count_value] * (current_layer.strength * filter_strength * subfilter_value) != 0f)
					{
						preterrain.color[count_value] = preterrain.color[count_value] / (color[count_value] * (current_layer.strength * filter_strength * subfilter_value));
					}
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						if (preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value) != 0f)
						{
							preterrain.splat[count_value] = preterrain.splat[count_value] / (preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value));
						}
					}
					break;
				}
				count_value = 0;
				while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
				{
					if (color2[count_value] * (current_layer.strength * filter_strength * subfilter_value) != 0f)
					{
						int num15 = current_layer.splat_output.splat[count_value];
						preterrain.splat[num15] = preterrain.splat[num15] / (color2[count_value] * (current_layer.strength * filter_strength * subfilter_value));
					}
					count_value++;
				}
			}
			else
			{
				if (current_layer.output != layer_output_enum.grass)
				{
					break;
				}
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					if (current_layer.grass_output.grass_calc[current_layer.grass_output.grass[count_value].prototypeindex] * (current_layer.strength * subfilter_value) != 0f)
					{
						preterrain.grass[count_value] = preterrain.grass[count_value] / current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value);
					}
				}
			}
			break;
		case condition_output_enum.average:
			if (current_layer.output == layer_output_enum.heightmap)
			{
				filter_value += filter_input * filter_strength * subfilter_value / (float)current_layer.prefilter.filter_index.Count;
			}
			else
			{
				filter_value += filter_input / (float)current_layer.prefilter.filter_index.Count;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < 3; count_value++)
				{
					preterrain.color[count_value] = preterrain.color[count_value] + color[0] * (current_layer.strength * filter_strength * subfilter_value) / (float)current_layer.prefilter.filter_index.Count;
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat[count_value] + preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value) / (float)current_layer.prefilter.filter_index.Count;
					}
					break;
				}
				count_value = 0;
				while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
				{
					int num10 = current_layer.splat_output.splat[count_value];
					preterrain.splat[num10] = preterrain.splat[num10] + color2[count_value] * (current_layer.strength * filter_strength * subfilter_value) / (float)current_layer.prefilter.filter_index.Count;
					count_value++;
				}
			}
			else if (current_layer.output == layer_output_enum.grass)
			{
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] = preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] + current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value) / (float)current_layer.prefilter.filter_index.Count;
				}
			}
			break;
		case condition_output_enum.difference:
			if (current_layer.output == layer_output_enum.heightmap)
			{
				filter_value = Mathf.Abs(filter_value - filter_input * filter_strength * subfilter_value);
			}
			else
			{
				filter_value = Mathf.Abs(filter_value - filter_input);
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < 3; count_value++)
				{
					preterrain.color[count_value] = Mathf.Abs(preterrain.color[count_value] - color[0] * (current_layer.strength * filter_strength * subfilter_value));
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = Mathf.Abs(preterrain.splat[count_value] - preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value));
					}
					break;
				}
				count_value = 0;
				while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
				{
					int num13 = current_layer.splat_output.splat[count_value];
					preterrain.splat[num13] = preterrain.splat[num13] + Mathf.Abs(preterrain.splat[count_value] - color2[count_value] * (current_layer.strength * filter_strength * subfilter_value));
					count_value++;
				}
			}
			else if (current_layer.output == layer_output_enum.grass)
			{
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] = Mathf.Abs(preterrain.grass[count_value] - current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value));
				}
			}
			break;
		case condition_output_enum.max:
			if (filter_input * filter_strength * subfilter_value <= filter_value)
			{
				break;
			}
			if (current_layer.output == layer_output_enum.heightmap)
			{
				filter_value = filter_input * filter_strength * subfilter_value;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < 3; count_value++)
				{
					preterrain.color[count_value] = color[count_value] * (current_layer.strength * filter_strength * subfilter_value);
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value);
					}
				}
				else
				{
					count_value = 0;
					while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
					{
						preterrain.splat[current_layer.splat_output.splat[count_value]] = color2[count_value] * (current_layer.strength * filter_strength * subfilter_value);
						count_value++;
					}
				}
			}
			if (current_layer.output == layer_output_enum.grass)
			{
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] = current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value);
				}
			}
			break;
		case condition_output_enum.min:
			if (filter_input * filter_strength * subfilter_value >= filter_value)
			{
				break;
			}
			if (current_layer.output == layer_output_enum.heightmap)
			{
				filter_value = filter_input * filter_strength * subfilter_value;
			}
			else
			{
				filter_value = filter_input;
			}
			if (filter.combine)
			{
				filter_combine = filter_value - filter_combine_start;
				break;
			}
			if (current_layer.output == layer_output_enum.color)
			{
				for (count_value = 0; count_value < 3; count_value++)
				{
					preterrain.color[count_value] = color[count_value] * (current_layer.strength * filter_strength * subfilter_value);
				}
			}
			if (current_layer.output == layer_output_enum.splat)
			{
				if (!flag)
				{
					for (count_value = 0; count_value < preterrain.splat.Length; count_value++)
					{
						preterrain.splat[count_value] = preterrain.splat_calc[count_value] * (current_layer.strength * filter_strength * subfilter_value);
					}
				}
				else
				{
					count_value = 0;
					while (count_value < 4 && count_value <= preterrain.splat.Length - 1)
					{
						preterrain.splat[current_layer.splat_output.splat[count_value]] = color2[count_value] * (current_layer.strength * filter_strength * subfilter_value);
						count_value++;
					}
				}
			}
			else if (current_layer.output == layer_output_enum.grass)
			{
				for (count_value = 0; count_value < current_layer.grass_output.grass.Count; count_value++)
				{
					preterrain.grass[current_layer.grass_output.grass[count_value].prototypeindex] = current_layer.grass_output.grass_calc[count_value] * (current_layer.strength * subfilter_value);
				}
			}
			break;
		}
	}

	public void calc_subfilter_value(filter_class filter, subfilter_class subfilter, float counter_y, float x)
	{
		float num = 0f;
		float num2 = UnityEngine.Random.Range(0f, 1f);
		float num3 = default(float);
		float num4 = default(float);
		int num5 = default(int);
		switch (subfilter.type)
		{
		case condition_type_enum.RandomRange:
			if (!(random_range < subfilter.range_start) && !(random_range > subfilter.range_end))
			{
				num = num2;
				subfilter.range_count++;
			}
			break;
		case condition_type_enum.Random:
			num = num2;
			break;
		case condition_type_enum.Height:
			num = height;
			break;
		case condition_type_enum.Steepness:
			num = degree / 90f;
			break;
		case condition_type_enum.Always:
			num = subfilter.curve_position;
			break;
		case condition_type_enum.Image:
			color = calc_image_value(subfilter.preimage, layer_x, layer_y);
			if (!subfilter.preimage.output)
			{
				break;
			}
			num = subfilter.preimage.output_pos;
			if (current_layer.output != layer_output_enum.tree || !subfilter.from_tree)
			{
				break;
			}
			tree_color[0] = color[0] * subfilter.strength;
			tree_color[1] = color[1] * subfilter.strength;
			tree_color[2] = color[2] * subfilter.strength;
			for (num5 = 0; num5 < subfilter.precurve_list.Count; num5++)
			{
				if (subfilter.precurve_list[num5].type == curve_type_enum.Normal)
				{
					tree_color[0] = subfilter.precurve_list[num5].curve.Evaluate(tree_color[0]);
					tree_color[1] = subfilter.precurve_list[num5].curve.Evaluate(tree_color[1]);
					tree_color[2] = subfilter.precurve_list[num5].curve.Evaluate(tree_color[2]);
				}
			}
			break;
		case condition_type_enum.RawHeightmap:
			calc_raw_value(subfilter.raw, layer_x, layer_y);
			num = subfilter.raw.output_pos;
			break;
		case condition_type_enum.MaxCount:
			if (subfilter.output_count >= subfilter.output_max)
			{
				subfilter_value = 0f;
				return;
			}
			if (!(subfilter_value < subfilter.output_count_min))
			{
				subfilter.output_count++;
			}
			break;
		case condition_type_enum.Splatmap:
			if (splat_output)
			{
				num = preterrain.splat_layer[subfilter.splat_index];
				if (!(num >= subfilter.curve_position))
				{
					num = 0f;
				}
			}
			else if (subfilter.splatmap < preterrain.splat_alpha.Length)
			{
				color = preterrain.splat_alpha[subfilter.splatmap].GetPixel(map_x, map_y);
				num = color[subfilter.splat_index - subfilter.splatmap * 4];
				if (!(num >= subfilter.curve_position))
				{
					num = 0f;
				}
			}
			else
			{
				num = 1f;
			}
			break;
		case condition_type_enum.RayCast:
			if (subfilter.raycast_mode == raycast_mode_enum.Hit)
			{
				if (Physics.SphereCast(new Vector3(x + prelayer.prearea.step.x / 2f, height * preterrain.size.y + subfilter.cast_height, prelayer.counter_y), prelayer.prearea.step.x / 2f * subfilter.ray_radius, subfilter.ray_direction, out hit, subfilter.ray_length, subfilter.layerMask))
				{
					layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
					num = (((layerHit & subfilter.layerMask) == 0) ? 1f : 0f);
				}
				else
				{
					num = 1f;
				}
			}
			else
			{
				if (subfilter.raycast_mode != raycast_mode_enum.Height)
				{
					break;
				}
				if (Physics.Raycast(new Vector3(x + prelayer.prearea.step.x / 2f, subfilter.cast_height, prelayer.counter_y), subfilter.ray_direction, out hit, subfilter.ray_length, subfilter.layerMask))
				{
					layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
					if ((layerHit & subfilter.layerMask) != 0)
					{
						Vector3 point = hit.point;
						float y = point.y;
						Vector3 size = preterrain.terrain.terrainData.size;
						num = y / size.y;
					}
					else
					{
						num = 0f;
					}
				}
				else
				{
					num = 0f;
				}
			}
			break;
		}
		for (num5 = 0; num5 < subfilter.precurve_list.Count; num5++)
		{
			switch (subfilter.precurve_list[num5].type)
			{
			case curve_type_enum.Normal:
				num = subfilter.precurve_list[num5].curve.Evaluate(num);
				break;
			case curve_type_enum.Random:
				num3 = subfilter.precurve_list[num5].curve.Evaluate(num);
				num = (subfilter.precurve_list[num5].abs ? (num + UnityEngine.Random.Range(0f, num3)) : (num + UnityEngine.Random.Range(0f - num3, num3)));
				break;
			case curve_type_enum.Perlin:
			{
				Vector2 vector = default(Vector2);
				vector = ((!subfilter.precurve_list[num5].rotation) ? new Vector2(x, counter_y) : calc_rotation_pixel(x, counter_y, 0f, 0f, 0f - subfilter.precurve_list[num5].rotation_value));
				num4 = subfilter.precurve_list[num5].curve.Evaluate(num);
				num3 = perlin_noise(vector.x, vector.y, subfilter.precurve_list[num5].offset.x, subfilter.precurve_list[num5].offset.y, subfilter.precurve_list[num5].frequency, subfilter.precurve_list[num5].detail, subfilter.precurve_list[num5].detail_strength) * num4 * subfilter.precurve_list[num5].strength;
				num = (subfilter.precurve_list[num5].abs ? (num + num3) : (num + (num3 * 2f - num4)));
				break;
			}
			}
		}
		if (subfilter.mode != 0)
		{
			float num6 = filter_input;
			float num7 = filter_input;
			int num8 = (int)((x - prelayer.prearea.area.xMin) / prelayer.prearea.step.x);
			if (!(Mathf.Abs((float)num8 - filter.last_pos_x) > prelayer.prearea.step.x))
			{
				if (subfilter.mode == subfilter_mode_enum.smooth)
				{
					num6 = Mathf.SmoothStep(filter.last_value_x[0], num6, 1f - num) * subfilter.strength;
				}
				if (subfilter.mode == subfilter_mode_enum.lerp)
				{
					num6 = Mathf.Lerp(filter.last_value_x[0], num6, 1f - num) * subfilter.strength;
				}
			}
			for (int i = 0; i < terrains.Count; i++)
			{
				if (terrains[i].rect.Contains(new Vector2(Mathf.Round(x / preterrain.heightmap_conversion.x) * preterrain.heightmap_conversion.x, counter_y + preterrain.heightmap_conversion.y)) && i == preterrain.index)
				{
					if (subfilter.mode == subfilter_mode_enum.smooth)
					{
						num7 = Mathf.SmoothStep(filter.last_value_y[num8], num7, 1f - num) * subfilter.strength;
					}
					else if (subfilter.mode == subfilter_mode_enum.lerp)
					{
						num7 = Mathf.Lerp(filter.last_value_y[num8], num7, 1f - num) * subfilter.strength;
					}
				}
			}
			filter_input = (num6 + num7) / 2f;
			return;
		}
		switch (subfilter.output)
		{
		case subfilter_output_enum.add:
			subfilter_value += num * subfilter.strength;
			break;
		case subfilter_output_enum.subtract:
			subfilter_value -= num * subfilter.strength;
			break;
		case subfilter_output_enum.min:
			if (!(num * subfilter.strength >= subfilter_value))
			{
				subfilter_value = num * subfilter.strength + subfilter_value * (1f - subfilter.strength);
			}
			break;
		case subfilter_output_enum.max:
			if (!(num * subfilter.strength <= subfilter_value))
			{
				subfilter_value = num * subfilter.strength + subfilter_value * (1f - subfilter.strength);
			}
			break;
		case subfilter_output_enum.average:
			subfilter_value += num * subfilter.strength / (float)filter.presubfilter.subfilter_index.Count;
			break;
		}
	}

	public void getRawTerrainTile(raw_class raw)
	{
		if (raw.flipTotalY)
		{
			raw.raw_number = (int)(preterrain.tiles.x * preterrain.tiles.y - (float)(preterrain.index_old + 1));
			if (!raw.flipTotalX)
			{
				int num = (int)(Mathf.Floor((float)raw.raw_number / preterrain.tiles.x) * preterrain.tiles.x);
				raw.raw_number = (int)((float)(num + num) + preterrain.tiles.x - (float)(raw.raw_number + 1));
			}
		}
		else
		{
			raw.raw_number = preterrain.index_old;
			if (raw.flipTotalX)
			{
				int num = (int)(Mathf.Floor((float)raw.raw_number / preterrain.tiles.x) * preterrain.tiles.x);
				raw.raw_number = (int)((float)(num + num) + preterrain.tiles.x - (float)(raw.raw_number + 1));
			}
		}
		if (raw.raw_number > raw.file_index.Count - 1)
		{
			raw.raw_number = 0;
		}
	}

	public float Fraq(float v)
	{
		return v - Mathf.Floor(v);
	}

	public void calc_raw_value(raw_class raw, float local_x, float local_y)
	{
		if (raw.raw_list_mode == list_condition_enum.Terrain)
		{
			getRawTerrainTile(raw);
		}
		if (raw.raw_number > raw.file_index.Count - 1)
		{
			raw.raw_number = 0;
		}
		Vector2 vector = default(Vector2);
		Vector2 vector2 = default(Vector2);
		Vector2 vector3 = default(Vector2);
		float num = 0f;
		float num2 = 0f;
		float num3 = 1f;
		float num4 = 1f;
		raw_file_class raw_file_class = raw_files[raw.file_index[raw.raw_number]];
		if (raw.flip_x)
		{
			num3 = -1f;
			num = raw_files[raw.file_index[raw.raw_number]].resolution.x - 1f;
		}
		if (!raw.flip_y)
		{
			num4 = -1f;
			num2 = raw_files[raw.file_index[raw.raw_number]].resolution.y - 1f;
		}
		if (raw.raw_mode == image_mode_enum.MultiTerrain)
		{
			if (settings.showMeshes)
			{
				vector.x = Mathf.Round(((raw_files[raw.file_index[raw.raw_number]].resolution.x - 1f) / meshes_area.area.width * (prelayer.x - meshes_area.area.xMin) * num3 - raw.tile_offset_x + num) / raw.tile_x);
				vector.y = Mathf.Round(((raw_files[raw.file_index[raw.raw_number]].resolution.y - 1f) / meshes_area.area.height * (prelayer.counter_y - meshes_area.area.yMin) * num4 - raw.tile_offset_y + num2) / raw.tile_y);
			}
			else
			{
				float num5 = default(float);
				float num6 = default(float);
				num5 = (raw_files[raw.file_index[raw.raw_number]].resolution.x - 1f) / preterrain.tiles.x * preterrain.tile_x;
				num6 = (raw_files[raw.file_index[raw.raw_number]].resolution.y - 1f) / preterrain.tiles.y * preterrain.tile_z;
				vector.x = Mathf.Round(((local_x / raw.conversion_step.x + num5) * num3 - raw.tile_offset_x + num) / raw.tile_x);
				vector.y = Mathf.Round(((local_y / raw.conversion_step.y + num6) * num4 - raw.tile_offset_y + num2) / raw.tile_y);
			}
		}
		else if (raw.raw_mode == image_mode_enum.Terrain)
		{
			if (settings.showMeshes)
			{
				vector.x = Mathf.Round(((raw_files[raw.file_index[raw.raw_number]].resolution.x - 1f) / premesh.area.width * (prelayer.x - premesh.area.xMin) * num3 - raw.tile_offset_x + num) / raw.tile_x);
				vector.y = Mathf.Round(((raw_files[raw.file_index[raw.raw_number]].resolution.y - 1f) / premesh.area.height * (prelayer.counter_y - premesh.area.yMin) * num4 - raw.tile_offset_y + num2) / raw.tile_y);
			}
			else
			{
				vector.x = (local_x / raw.conversion_step.x * num3 - raw.tile_offset_x + num) / raw.tile_x;
				vector.y = (local_y / raw.conversion_step.y * num4 - raw.tile_offset_y + num2) / raw.tile_y;
			}
		}
		else if (settings.showMeshes)
		{
			vector.x = Mathf.Round(((raw_files[raw.file_index[raw.raw_number]].resolution.x - 1f) / premesh.area.width * (prelayer.x - premesh.area.xMin) * num3 - raw.tile_offset_x + num) / raw.tile_x);
			vector.y = Mathf.Round(((raw_files[raw.file_index[raw.raw_number]].resolution.y - 1f) / premesh.area.height * (prelayer.counter_y - premesh.area.yMin) * num4 - raw.tile_offset_y + num2) / raw.tile_y);
		}
		else
		{
			vector.x = ((local_x - prelayer.prearea.area_old.x) / raw.conversion_step.x * num3 - raw.tile_offset_x + num) / raw.tile_x;
			vector.y = ((local_y - prelayer.prearea.area_old.y) / raw.conversion_step.y * num4 - raw.tile_offset_y + num2) / raw.tile_y;
		}
		if (raw.rotation)
		{
			vector = calc_rotation_pixel(vector.x, vector.y, raw_files[raw.file_index[raw.raw_number]].resolution.x / 2f / raw.conversion_step.x, raw_files[raw.file_index[raw.raw_number]].resolution.y / 2f / raw.conversion_step.y, raw.rotation_value);
		}
		vector2.x = Mathf.Floor(vector.x);
		vector2.y = Mathf.Floor(vector.y);
		vector3.x = Mathf.Ceil(vector.x);
		vector3.y = Mathf.Ceil(vector.y);
		float num7 = vector.x - vector2.x;
		float num8 = vector.y - vector2.y;
		if (raw.clamp)
		{
			if (vector2.x < 0f || !(vector2.x < raw_file_class.resolution.x))
			{
				raw.output_pos = 0f;
				return;
			}
			if (vector2.y < 0f || !(vector2.y < raw_file_class.resolution.y))
			{
				raw.output_pos = 0f;
				return;
			}
			if (vector3.x < 0f || !(vector3.x < raw_file_class.resolution.x))
			{
				raw.output_pos = 0f;
				return;
			}
			if (vector3.y < 0f || !(vector3.y < raw_file_class.resolution.y))
			{
				raw.output_pos = 0f;
				return;
			}
		}
		else
		{
			vector2 = new Vector2(Mathf.Round(Fraq(vector2.x / raw_file_class.resolution.x) * raw_file_class.resolution.x), Mathf.Round(Fraq(vector2.y / raw_file_class.resolution.y) * raw_file_class.resolution.y));
			vector3 = new Vector2(Mathf.Round(Fraq(vector3.x / raw_file_class.resolution.x) * raw_file_class.resolution.x), Mathf.Round(Fraq(vector3.y / raw_file_class.resolution.y) * raw_file_class.resolution.y));
		}
		int num9 = (int)(vector2.y * raw_files[raw.file_index[raw.raw_number]].resolution.x * 2f + vector2.x * 2f);
		int num10 = (int)(vector2.y * raw_files[raw.file_index[raw.raw_number]].resolution.x * 2f + vector3.x * 2f);
		int num11 = (int)(vector3.y * raw_files[raw.file_index[raw.raw_number]].resolution.x * 2f + vector2.x * 2f);
		int num12 = (int)(vector3.y * raw_files[raw.file_index[raw.raw_number]].resolution.x * 2f + vector3.x * 2f);
		if (num9 > raw_files[raw.file_index[raw.raw_number]].bytes.Length - 1)
		{
			UnityEngine.Debug.Log("The Raw Heightmap file '" + raw_files[raw.file_index[raw.raw_number]].file + "' has a lower resolution than selected. Please check the File size. It should be X*Y*2 = " + raw_files[raw.file_index[raw.raw_number]].resolution.x + "*" + raw_files[raw.file_index[raw.raw_number]].resolution.y + "*2 = " + raw_files[raw.file_index[raw.raw_number]].resolution.x * raw_files[raw.file_index[raw.raw_number]].resolution.y * 2f + " Bytes (" + raw_files[raw.file_index[raw.raw_number]].resolution.x + "*" + raw_files[raw.file_index[raw.raw_number]].resolution.y + " resolution). But the File size is " + raw_files[raw.file_index[raw.raw_number]].bytes.Length + " Bytes (" + Mathf.Round(Mathf.Sqrt(raw_files[raw.file_index[raw.raw_number]].bytes.Length / 2)) + "x" + Mathf.Round(Mathf.Sqrt(raw_files[raw.file_index[raw.raw_number]].bytes.Length / 2)) + " resolution).");
			prelayer.x = 1E+12f;
			prelayer.counter_y = -1E+11f;
			generate = false;
			return;
		}
		float num13 = default(float);
		float num14 = default(float);
		float num15 = default(float);
		float num16 = default(float);
		if (raw_files[raw.file_index[raw.raw_number]].mode == raw_mode_enum.Mac)
		{
			num13 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num9] * 256f + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num9 + 1]) / 65535f;
			num14 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num10] * 256f + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num10 + 1]) / 65535f;
			num15 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num11] * 256f + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num11 + 1]) / 65535f;
			num16 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num12] * 256f + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num12 + 1]) / 65535f;
		}
		else if (raw_files[raw.file_index[raw.raw_number]].mode == raw_mode_enum.Windows)
		{
			num13 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num9] + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num9 + 1] * 256f) / 65535f;
			num14 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num10] + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num10 + 1] * 256f) / 65535f;
			num15 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num11] + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num11 + 1] * 256f) / 65535f;
			num16 = ((float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num12] + (float)(int)raw_files[raw.file_index[raw.raw_number]].bytes[num12 + 1] * 256f) / 65535f;
		}
		float num17 = num13 + (num14 - num13) * num7;
		float num18 = num15 + (num16 - num15) * num7;
		raw.output_pos = num17 + (num18 - num17) * num8;
	}

	public void generate_filter(filter_class filter)
	{
		layer_class layer_class = new layer_class();
		Rect area = terrains[0].prearea.area;
		Vector2 vector = new Vector2(area.width / 128f, area.height / 128f);
		Color color = new Color(1f, 1f, 1f, 1f);
		current_layer = layer_class;
		current_layer.output = layer_output_enum.heightmap;
		for (float num = area.yMin; num < area.yMax; num += vector.y)
		{
			for (float num2 = area.xMin; num2 < area.xMax; num2 += vector.x)
			{
				filter_value = 0f;
				calc_filter_value(filter, num, num2);
				color[0] = filter_value;
				color[1] = filter_value;
				color[2] = filter_value;
				filter.preview_texture.SetPixel((int)(num2 / vector.x), (int)(num / vector.y), color);
			}
		}
		filter.preview_texture.Apply();
	}

	public void set_image_terrain_mode(int terrain_index)
	{
		for (int i = 0; i < filter.Count; i++)
		{
			if (filter[i].type == condition_type_enum.Image && filter[i].preimage.image_list_mode == list_condition_enum.Terrain && !filter[i].preimage.short_list)
			{
				filter[i].preimage.image_number = terrains[terrain_index].index_old;
				if (filter[i].preimage.image_number > filter[i].preimage.image.Count - 1)
				{
					filter[i].preimage.image_number = filter[i].preimage.image.Count - 1;
				}
			}
		}
		for (int j = 0; j < subfilter.Count; j++)
		{
			if (subfilter[j].type == condition_type_enum.Image && subfilter[j].preimage.image_list_mode == list_condition_enum.Terrain && !subfilter[j].preimage.short_list)
			{
				subfilter[j].preimage.image_number = terrains[terrain_index].index_old;
				if (subfilter[j].preimage.image_number > subfilter[j].preimage.image.Count - 1)
				{
					subfilter[j].preimage.image_number = subfilter[j].preimage.image.Count - 1;
				}
			}
		}
	}

	public Color get_image_pixel(image_class preimage, float local_x, float local_y)
	{
		Color result;
		if (!preimage.image[preimage.image_number])
		{
			result = new Color(0f, 0f, 0f);
		}
		else
		{
			float num = 0f;
			float num2 = 0f;
			float num3 = 1f;
			float num4 = 1f;
			Color color = default(Color);
			local_x -= prelayer.prearea.image_offset.x;
			local_y -= prelayer.prearea.image_offset.y;
			if (preimage.flip_x)
			{
				num3 = -1f;
				num = preimage.image[preimage.image_number].width - 1;
			}
			if (preimage.flip_y)
			{
				num4 = -1f;
				num2 = preimage.image[preimage.image_number].height - 1;
			}
			if (preimage.image_mode == image_mode_enum.Terrain)
			{
				if (settings.showMeshes)
				{
					imagePosition.x = Mathf.Round(((float)preimage.image[preimage.image_number].width / premesh.area.width * (prelayer.x - premesh.area.xMin) * num3 - preimage.tile_offset_x + num) / preimage.tile_x);
					imagePosition.y = Mathf.Round(((float)preimage.image[preimage.image_number].height / premesh.area.height * (prelayer.counter_y - premesh.area.yMin) * num4 - preimage.tile_offset_y + num2) / preimage.tile_y);
				}
				else
				{
					imagePosition.x = Mathf.Round((local_x / preimage.conversion_step.x * num3 - preimage.tile_offset_x + num) / preimage.tile_x);
					imagePosition.y = Mathf.Round((local_y / preimage.conversion_step.y * num4 - preimage.tile_offset_y + num2) / preimage.tile_y);
				}
			}
			else if (preimage.image_mode == image_mode_enum.MultiTerrain)
			{
				if (settings.showMeshes)
				{
					imagePosition.x = Mathf.Round(((float)preimage.image[preimage.image_number].width / meshes_area.area.width * (prelayer.x - meshes_area.area.xMin) * num3 - preimage.tile_offset_x + num) / preimage.tile_x);
					imagePosition.y = Mathf.Round(((float)preimage.image[preimage.image_number].height / meshes_area.area.height * (prelayer.counter_y - meshes_area.area.yMin) * num4 - preimage.tile_offset_y + num2) / preimage.tile_y);
				}
				else
				{
					float num5 = default(float);
					float num6 = default(float);
					num5 = (float)preimage.image[preimage.image_number].width / preterrain.tiles.x * preterrain.tile_x;
					num6 = (float)preimage.image[preimage.image_number].height / preterrain.tiles.y * preterrain.tile_z;
					imagePosition.x = Mathf.Round(((local_x / preimage.conversion_step.x + num5) * num3 - preimage.tile_offset_x + num) / preimage.tile_x);
					imagePosition.y = Mathf.Round(((local_y / preimage.conversion_step.y + num6) * num4 - preimage.tile_offset_y + num2) / preimage.tile_y);
				}
			}
			else if (settings.showMeshes)
			{
				imagePosition.x = Mathf.Round(((float)preimage.image[preimage.image_number].width / premesh.area.width * (prelayer.x - premesh.area.xMin) * num3 - preimage.tile_offset_x + num) / preimage.tile_x);
				imagePosition.y = Mathf.Round(((float)preimage.image[preimage.image_number].height / premesh.area.height * (prelayer.counter_y - premesh.area.yMin) * num4 - preimage.tile_offset_y + num2) / preimage.tile_y);
			}
			else
			{
				imagePosition.x = ((local_x - prelayer.prearea.area_old.x) / preimage.conversion_step.x * num3 - preimage.tile_offset_x + num) / preimage.tile_x;
				imagePosition.y = ((local_y - prelayer.prearea.area_old.y) / preimage.conversion_step.y * num4 - preimage.tile_offset_y + num2) / preimage.tile_y;
			}
			if (preimage.rotation)
			{
				imagePosition = calc_rotation_pixel(imagePosition.x, imagePosition.y, (float)(preimage.image[preimage.image_number].width / 2) / preimage.conversion_step.x, (float)(preimage.image[preimage.image_number].height / 2) / preimage.conversion_step.y, preimage.rotation_value);
			}
			bool flag = true;
			color = ((!preimage.clamp) ? preimage.image[preimage.image_number].GetPixel((int)imagePosition.x, (int)imagePosition.y) : ((!(imagePosition.x > (float)preimage.image[preimage.image_number].width) && !(imagePosition.x < 0f) && !(imagePosition.y > (float)preimage.image[preimage.image_number].height) && imagePosition.y >= 0f) ? preimage.image[preimage.image_number].GetPixel((int)imagePosition.x, (int)imagePosition.y) : Color.black));
			color *= preimage.image_color;
			result = color;
		}
		return result;
	}

	public Color calc_image_value(image_class preimage, float local_x, float local_y)
	{
		Color color = get_image_pixel(preimage, local_x, local_y);
		float output_pos = default(float);
		preimage.output = true;
		preimage.output_pos = color[0];
		if (!preimage.edge_blur || current_layer.output != layer_output_enum.splat)
		{
			if (preimage.precolor_range.color_range.Count > 0)
			{
				preimage.output = false;
				for (count_color_range = 0; count_color_range < preimage.precolor_range.color_range.Count; count_color_range++)
				{
					Color color_start = preimage.precolor_range.color_range[count_color_range].color_start;
					Color color_end = preimage.precolor_range.color_range[count_color_range].color_end;
					if (preimage.select_mode == select_mode_enum.free)
					{
						output_pos = preimage.precolor_range.color_range[count_color_range].output;
					}
					else
					{
						switch (current_layer.output)
						{
						case layer_output_enum.color:
							output_pos = current_layer.color_output.precolor_range[0].color_range_value.select_value[preimage.precolor_range.color_range[count_color_range].select_output];
							break;
						case layer_output_enum.splat:
							if (current_layer.splat_output.splat.Count > 0)
							{
								output_pos = current_layer.splat_output.splat_value.select_value[preimage.precolor_range.color_range[count_color_range].select_output];
							}
							break;
						case layer_output_enum.tree:
							output_pos = current_layer.tree_output.tree_value.select_value[preimage.precolor_range.color_range[count_color_range].select_output];
							break;
						case layer_output_enum.grass:
							output_pos = current_layer.grass_output.grass_value.select_value[preimage.precolor_range.color_range[count_color_range].select_output];
							break;
						case layer_output_enum.@object:
							output_pos = current_layer.object_output.object_value.select_value[preimage.precolor_range.color_range[count_color_range].select_output];
							break;
						}
					}
					if (preimage.precolor_range.color_range[count_color_range].one_color)
					{
						if (preimage.precolor_range.color_range[count_color_range].color_start == color && !preimage.precolor_range.color_range[count_color_range].invert)
						{
							preimage.output_pos = output_pos;
							preimage.output = true;
						}
						else if (preimage.precolor_range.color_range[count_color_range].invert)
						{
							preimage.output_pos = output_pos;
							preimage.output = true;
						}
					}
					else if (color_in_range(color, color_start, color_end))
					{
						if (!preimage.precolor_range.color_range[count_color_range].invert)
						{
							if (preimage.select_mode == select_mode_enum.free)
							{
								preimage.output_pos = preimage.precolor_range.color_range[count_color_range].curve.Evaluate(calc_color_pos(color, color_start, color_end));
							}
							else
							{
								preimage.output_pos = output_pos;
								preimage.output_alpha = calc_color_pos(color, color_start, color_end);
								filter_strength = calc_color_pos(color, color_start, color_end);
							}
							preimage.output = true;
						}
					}
					else if (preimage.precolor_range.color_range[count_color_range].invert)
					{
						if (preimage.select_mode == select_mode_enum.free)
						{
							preimage.output_pos = 1f - preimage.precolor_range.color_range[count_color_range].curve.Evaluate(calc_color_pos(color, color_start, color_end));
							preimage.output = true;
						}
						else
						{
							preimage.output_pos = output_pos;
							preimage.output_alpha = calc_color_pos(color, color_start, color_end);
						}
					}
				}
			}
		}
		else
		{
			float num = default(float);
			float edge_blur_radius = preimage.edge_blur_radius;
			float num2 = edge_blur_radius * 2f + 1f;
			int num3 = default(int);
			imagePosition.x -= edge_blur_radius;
			imagePosition.y -= edge_blur_radius;
			if (!(imagePosition.x >= 0f))
			{
				imagePosition.x = 0f;
				num2 -= edge_blur_radius;
			}
			if (!(imagePosition.y >= 0f))
			{
				imagePosition.y = 0f;
				num2 -= edge_blur_radius;
			}
			if (!(imagePosition.x <= (float)preimage.image[preimage.image_number].width - num2 - 1f))
			{
				imagePosition.x = (float)preimage.image[preimage.image_number].width - num2 - 1f;
				num2 -= edge_blur_radius;
			}
			if (!(imagePosition.y <= (float)preimage.image[preimage.image_number].height - num2 - 1f))
			{
				imagePosition.y = (float)preimage.image[preimage.image_number].height - num2 - 1f;
				num2 -= edge_blur_radius;
			}
			Color[] pixels = preimage.image[preimage.image_number].GetPixels((int)imagePosition.x, (int)imagePosition.y, (int)num2, (int)num2);
			for (int i = 0; i < preterrain.splat.Length; i++)
			{
				preterrain.splat_calc[i] = 0f;
			}
			for (int j = 0; j < pixels.Length; j++)
			{
				if (current_layer.splat_output.splat.Count <= 0)
				{
					continue;
				}
				for (count_color_range = 0; count_color_range < preimage.precolor_range.color_range.Count; count_color_range++)
				{
					if (pixels[j] == preimage.precolor_range.color_range[count_color_range].color_start)
					{
						num3 = ((preimage.select_mode != 0) ? preimage.precolor_range.color_range[count_color_range].select_output : ((int)preimage.precolor_range.color_range[count_color_range].output));
						if (!current_layer.splat_output.splat_custom[num3].custom)
						{
							output_pos = current_layer.splat_output.splat[num3];
							preterrain.splat_calc[(int)output_pos] = preterrain.splat_calc[(int)output_pos] + 1f / ((float)pixels.Length * 1f);
						}
						else
						{
							for (int k = 0; k < preterrain.splat_calc.Length; k++)
							{
								preterrain.splat_calc[k] = preterrain.splat_calc[k] + 1f / ((float)pixels.Length * 1f) * (current_layer.splat_output.splat_custom[num3].value[k] / current_layer.splat_output.splat_custom[num3].totalValue);
							}
						}
					}
				}
			}
		}
		return color;
	}

	public void loop_prelayer(string command, int index, bool loop_inactive)
	{
		bool flag = false;
		bool image_auto_scale = false;
		bool texture_resize_null = false;
		bool flag2 = false;
		bool store_last_values = false;
		bool unload_texture = false;
		bool flag3 = false;
		bool flag4 = false;
		bool flag5 = false;
		bool flag6 = false;
		bool flag7 = false;
		bool flag8 = false;
		bool flag9 = false;
		bool check_measure_normal = false;
		bool flag10 = false;
		bool foldout_filter = false;
		bool foldout_subfilter = false;
		bool flag11 = false;
		bool set_as_default = false;
		bool flag12 = false;
		layer_output_enum layer_output_enum = default(layer_output_enum);
		bool flag13 = default(bool);
		int num = default(int);
		int num2 = default(int);
		int num3 = default(int);
		if (command.Contains("(ssc)"))
		{
			flag12 = true;
		}
		if (command.IndexOf("(gfc)") != -1)
		{
			flag11 = true;
		}
		if (command.IndexOf("(cmn)") != -1)
		{
			check_measure_normal = true;
		}
		if (command.IndexOf("(rsc") != -1)
		{
			flag9 = true;
		}
		if (command.IndexOf("(ias)") != -1)
		{
			image_auto_scale = true;
		}
		if (command.IndexOf("(trn)") != -1)
		{
			texture_resize_null = true;
		}
		if (command.IndexOf("(ed)") != -1)
		{
			flag2 = true;
		}
		if (command.IndexOf("(slv)") != -1)
		{
			store_last_values = true;
		}
		if (command.IndexOf("(ut)") != -1)
		{
			unload_texture = true;
		}
		if (command.IndexOf("(ocr)") != -1)
		{
			flag4 = true;
		}
		if (command.IndexOf("(asr)") != -1)
		{
			flag5 = true;
		}
		if (command.IndexOf("(cpo)") != -1)
		{
			flag = true;
		}
		if (command.IndexOf("(inf)") != -1)
		{
			flag7 = true;
		}
		if (command.IndexOf("(eho)") != -1)
		{
			flag8 = true;
		}
		if (command.IndexOf("(caf)") != -1)
		{
			flag10 = true;
		}
		if (command.IndexOf("(ff)") != -1)
		{
			foldout_filter = true;
		}
		if (command.IndexOf("(fs)") != -1)
		{
			foldout_subfilter = true;
		}
		if (command.IndexOf("(sad)") != -1)
		{
			set_as_default = true;
		}
		if (command.IndexOf("(fix)") != -1)
		{
			flag6 = true;
		}
		if (flag6 || flag7)
		{
			reset_link_filter();
			reset_link_subfilter();
			settings.prelayers_linked = 0;
			settings.filters_linked = 0;
			settings.subfilters_linked = 0;
		}
		if (command.IndexOf("(fl)") != -1)
		{
			if (command.IndexOf("(heightmap)") != -1)
			{
				layer_output_enum = layer_output_enum.heightmap;
			}
			else if (command.IndexOf("(color)") != -1)
			{
				layer_output_enum = layer_output_enum.color;
			}
			else if (command.IndexOf("(splat)") != -1)
			{
				layer_output_enum = layer_output_enum.splat;
			}
			else if (command.IndexOf("(tree)") != -1)
			{
				layer_output_enum = layer_output_enum.tree;
			}
			else if (command.IndexOf("(grass)") != -1)
			{
				layer_output_enum = layer_output_enum.grass;
			}
			else if (command.IndexOf("(object)") != -1)
			{
				layer_output_enum = layer_output_enum.@object;
			}
			if (command.IndexOf("(true)") != -1)
			{
				flag13 = true;
			}
			else if (command.IndexOf("(false)") != -1)
			{
				flag13 = false;
			}
			flag3 = true;
		}
		for (count_prelayer = 0; count_prelayer < prelayers.Count; count_prelayer++)
		{
			prelayer_class prelayer_class = prelayers[count_prelayer];
			if (flag5)
			{
				if (settings.showTerrains)
				{
					if (prelayers[count_prelayer].prearea.resolution_mode == resolution_mode_enum.Automatic)
					{
						select_automatic_step_resolution(terrains[0], prelayers[count_prelayer].prearea);
					}
					set_area_resolution(terrains[0], prelayers[count_prelayer].prearea);
					prelayers[count_prelayer].prearea.area_old = prelayers[count_prelayer].prearea.area;
					prelayers[count_prelayer].prearea.step_old = prelayers[count_prelayer].prearea.step;
				}
				else
				{
					select_automatic_step_resolution_mesh(prelayers[count_prelayer].prearea);
					set_area_resolution(prelayers[count_prelayer].prearea);
					prelayers[count_prelayer].prearea.area_old = prelayers[count_prelayer].prearea.area;
					prelayers[count_prelayer].prearea.step_old = prelayers[count_prelayer].prearea.step;
				}
			}
			if (flag9 || flag10)
			{
				for (int i = 0; i < prelayers[count_prelayer].predescription.description.Count; i++)
				{
					if (flag9)
					{
						prelayers[count_prelayer].predescription.description[i].swap_text = "S";
						prelayers[count_prelayer].predescription.description[i].swap_select = false;
						prelayers[count_prelayer].predescription.description[i].copy_select = false;
					}
					if (flag10)
					{
						prelayers[count_prelayer].predescription.description[i].foldout = false;
					}
				}
			}
			if (flag10)
			{
				prelayers[count_prelayer].prearea.foldout = false;
			}
			for (count_layer = 0; count_layer < prelayer_class.layer.Count; count_layer++)
			{
				layer_class layer_class = prelayer_class.layer[count_layer];
				if (flag2)
				{
					bool flag14 = false;
					if (!layer_class.active)
					{
						flag14 = true;
					}
					else if ((layer_class.output != layer_output_enum.color || !color_output) && (layer_class.output != layer_output_enum.splat || !splat_output) && (layer_class.output != layer_output_enum.tree || !tree_output) && (layer_class.output != layer_output_enum.grass || !grass_output) && (layer_class.output != layer_output_enum.@object || !object_output) && (layer_class.output != 0 || !heightmap_output))
					{
						flag14 = true;
					}
					if (flag14)
					{
						erase_layer(prelayer_class, count_layer, 0, 0, description: false, loop_layer: true, count_layer: false);
						count_layer--;
						continue;
					}
					if (layer_class.output == layer_output_enum.color)
					{
						for (int j = 0; j < layer_class.color_output.precolor_range.Count; j++)
						{
							for (int k = 0; k < layer_class.color_output.precolor_range[j].color_range.Count; k++)
							{
								if (!layer_class.color_output.precolor_range[j].color_range_value.active[k])
								{
									layer_class.color_output.precolor_range[j].erase_color_range(k);
									loop_prefilter_index(layer_class.prefilter, k);
									k--;
								}
							}
						}
					}
					else if (layer_class.output == layer_output_enum.splat)
					{
						for (num = 0; num < layer_class.splat_output.splat.Count; num++)
						{
							if (!layer_class.splat_output.splat_value.active[num] || layer_class.splat_output.splat[num] > terrains[0].terrain.terrainData.splatPrototypes.Length - 1)
							{
								layer_class.splat_output.erase_splat(num);
								loop_prefilter_index(layer_class.prefilter, num);
								num--;
							}
						}
					}
					else if (layer_class.output == layer_output_enum.grass)
					{
						for (int l = 0; l < layer_class.grass_output.grass_value.active.Count; l++)
						{
							if (!layer_class.grass_output.grass_value.active[l] || layer_class.grass_output.grass[l].prototypeindex > terrains[0].terrain.terrainData.detailPrototypes.Length - 1)
							{
								layer_class.grass_output.erase_grass(l);
								loop_prefilter_index(layer_class.prefilter, l);
								l--;
							}
						}
					}
				}
				if (flag12)
				{
					layer_class.splat_output.SyncSplatCustom(masterTerrain.splatPrototypes.Count);
				}
				if (flag9)
				{
					layer_class.swap_text = "S";
					layer_class.swap_select = false;
					layer_class.copy_select = false;
					layer_class.tree_output.placed = 0;
					layer_class.object_output.placed = 0;
					layer_class.text_placed = string.Empty;
					for (num2 = 0; num2 < layer_class.tree_output.tree.Count; num2++)
					{
						layer_class.tree_output.tree[num2].placed = 0;
					}
					for (num3 = 0; num3 < layer_class.object_output.@object.Count; num3++)
					{
						layer_class.object_output.@object[num3].placed = 0;
					}
				}
				if (flag10)
				{
					layer_class.foldout = false;
					layer_class.tree_output.foldout = false;
					for (num2 = 0; num2 < layer_class.tree_output.tree.Count; num2++)
					{
						layer_class.tree_output.tree[num2].foldout = false;
						layer_class.tree_output.tree[num2].scale_foldout = false;
						layer_class.tree_output.tree[num2].distance_foldout = false;
						layer_class.tree_output.tree[num2].data_foldout = false;
						layer_class.tree_output.tree[num2].precolor_range.foldout = false;
					}
					layer_class.object_output.foldout = false;
					for (num3 = 0; num3 < layer_class.object_output.@object.Count; num3++)
					{
						layer_class.object_output.@object[num3].foldout = false;
						layer_class.object_output.@object[num3].data_foldout = false;
						layer_class.object_output.@object[num3].transform_foldout = false;
						layer_class.object_output.@object[num3].settings_foldout = false;
						layer_class.object_output.@object[num3].distance_foldout = false;
						layer_class.object_output.@object[num3].rotation_foldout = false;
						layer_class.object_output.@object[num3].rotation_map_foldout = false;
					}
				}
				if (!layer_class.active && !loop_inactive)
				{
					continue;
				}
				if (flag8 && layer_class.output == layer_output_enum.heightmap)
				{
					if (layer_class.smooth)
					{
						smooth_command = true;
					}
					heightmap_output_layer = true;
				}
				if (flag3)
				{
					if (layer_class.output == layer_output_enum)
					{
						if (flag13)
						{
							layer_class.foldout = false;
						}
						else
						{
							layer_class.foldout = true;
						}
					}
					else
					{
						layer_class.foldout = false;
					}
				}
				for (num2 = 0; num2 < layer_class.tree_output.tree.Count; num2++)
				{
					if (flag2)
					{
						if (!layer_class.tree_output.tree_value.active[num2] || layer_class.tree_output.tree[num2].prototypeindex > terrains[0].terrain.terrainData.treePrototypes.Length - 1)
						{
							layer_class.tree_output.erase_tree(num2, this);
							loop_prefilter_index(layer_class.prefilter, num2);
							num2--;
							continue;
						}
						erase_deactive_color_range(layer_class.tree_output.tree[num2].precolor_range);
					}
					goto IL_0cb1;
					IL_0c8e:
					goto IL_0cb1;
					IL_0cb1:
					call_from = 1;
					loop_prefilter(layer_class.tree_output.tree[num2].prefilter, index, flag6, flag7, loop_inactive, image_auto_scale, texture_resize_null, unload_texture, flag2, store_last_values, flag9, check_measure_normal, flag10, foldout_filter, foldout_subfilter, set_as_default);
				}
				if (layer_class.output == layer_output_enum.@object)
				{
					for (num3 = 0; num3 < layer_class.object_output.@object.Count; num3++)
					{
						if (flag2 && (!layer_class.object_output.object_value.active[num3] || !layer_class.object_output.@object[num3].object1))
						{
							erase_object(prelayers[count_prelayer].layer[count_layer].object_output, num3);
							loop_prefilter_index(layer_class.prefilter, num3);
							num3--;
							continue;
						}
						object_class object_class = layer_class.object_output.@object[num3];
						if ((flag6 || flag7) && object_class.prelayer_created)
						{
							if (object_class.prelayer_index > prelayers.Count - 1)
							{
								if (!flag7)
								{
									UnityEngine.Debug.Log("Prelayer reference -> " + object_class.prelayer_index + " not found, erasing reference entry...");
									object_class.prelayer_created = false;
									object_class.prelayer_index = -1;
								}
							}
							else if (!flag7)
							{
								prelayers[object_class.prelayer_index].linked = true;
							}
							else
							{
								settings.prelayers_linked++;
							}
						}
						if (((layer_class.object_output.object_value.active[num3] && object_output) || loop_inactive) && flag)
						{
							if (flag4)
							{
								create_object_child_list(object_class);
							}
							if (object_class.parent_clear || loop_inactive)
							{
								clear_parent_object(object_class);
							}
						}
						if (object_class.rotation_map.active)
						{
							object_class.rotation_map.preimage.set_image_auto_scale(terrains[0], prelayers[count_prelayer].prearea.area_old, 0);
						}
					}
				}
				call_from = 0;
				loop_prefilter(layer_class.prefilter, index, flag6, flag7, loop_inactive, image_auto_scale, texture_resize_null, unload_texture, flag2, store_last_values, flag9, check_measure_normal, flag10, foldout_filter, foldout_subfilter, set_as_default);
			}
		}
		if (flag7 || flag6)
		{
			erase_unlinked_prelayer(flag6);
			erase_unlinked_filter(flag6);
			erase_unlinked_subfilter(flag6);
		}
	}

	public void loop_prefilter(prefilter_class prefilter1, int index, bool fix_database, bool info_database, bool loop_inactive, bool image_auto_scale, bool texture_resize_null, bool unload_texture, bool erase_deactive, bool store_last_values, bool reset_swap_copy, bool check_measure_normal, bool close_all_foldout, bool foldout_filter, bool foldout_subfilter, bool set_as_default)
	{
		if (close_all_foldout)
		{
			prefilter1.foldout = false;
		}
		for (count_filter = 0; count_filter < prefilter1.filter_index.Count; count_filter++)
		{
			filter_class filter_class = filter[prefilter1.filter_index[count_filter]];
			if (erase_deactive)
			{
				if (!filter_class.active)
				{
					erase_filter(count_filter, prefilter1);
					count_filter--;
					continue;
				}
				erase_deactive_color_range(filter_class.preimage.precolor_range);
				erase_deactive_animation_curve(filter_class.precurve_list);
			}
			goto IL_0091;
			IL_006f:
			goto IL_0091;
			IL_0091:
			if (fix_database || info_database)
			{
				if (prefilter1.filter_index[count_filter] > filter.Count - 1)
				{
					UnityEngine.Debug.Log("Filter reference -> " + prefilter1.filter_index[count_filter] + " not found, erasing reference entry...");
					if (!info_database)
					{
						erase_filter_reference(prefilter1, count_filter);
						count_filter--;
						continue;
					}
				}
				else if (filter[prefilter1.filter_index[count_filter]].linked)
				{
					UnityEngine.Debug.Log("Filter double linked -> " + prefilter1.filter_index[count_filter]);
					if (fix_database)
					{
						filter.Add(new filter_class());
						filter[filter.Count - 1] = copy_filter(filter[prefilter1.filter_index[count_filter]], copy_subfilter: true);
						prefilter1.filter_index[count_filter] = filter.Count - 1;
						continue;
					}
				}
				else
				{
					filter[prefilter1.filter_index[count_filter]].linked = true;
					if (filter[prefilter1.filter_index[count_filter]].linked)
					{
						settings.filters_linked++;
					}
				}
			}
			if (foldout_filter && prefilter1.filter_index[count_filter] == index)
			{
				int num = get_layer_description(prelayers[count_prelayer], count_layer);
				if (num != -1)
				{
					prelayers[count_prelayer].predescription.description[num].foldout = true;
				}
				prelayers[count_prelayer].foldout = true;
				prelayers[count_prelayer].layer[count_layer].foldout = true;
				if (call_from == 1)
				{
					prelayers[count_prelayer].layer[count_layer].tree_output.foldout = true;
					prelayers[count_prelayer].layer[count_layer].tree_output.tree[count_tree].foldout = true;
				}
				prefilter1.foldout = true;
				filter_class.foldout = true;
			}
			if (set_as_default)
			{
				for (int i = 0; i < filter_class.precurve_list.Count; i++)
				{
					filter_class.precurve_list[i].set_as_default();
				}
			}
			if (close_all_foldout)
			{
				filter_class.foldout = false;
				filter_class.presubfilter.foldout = false;
			}
			if (reset_swap_copy)
			{
				filter[prefilter1.filter_index[count_filter]].swap_text = "S";
				filter[prefilter1.filter_index[count_filter]].swap_select = false;
				filter[prefilter1.filter_index[count_filter]].copy_select = false;
			}
			if (check_measure_normal && filter_class.active && !measure_normal && filter_class.type == condition_type_enum.Direction)
			{
				measure_normal = true;
			}
			if (!filter_class.active && !loop_inactive)
			{
				continue;
			}
			if (image_auto_scale && filter_class.preimage.image_auto_scale && settings.showTerrains)
			{
				if (!prelayers[count_prelayer].prearea.active)
				{
					filter_class.preimage.set_image_auto_scale(terrains[0], terrains[0].prearea.area_old, 0);
				}
				else
				{
					filter_class.preimage.set_image_auto_scale(terrains[0], prelayers[count_prelayer].prearea.area_old, 0);
				}
			}
			if (unload_texture && filter_class.preimage.image.Count > 0)
			{
				for (int j = 0; j < filter_class.preimage.image.Count; j++)
				{
					if ((bool)current_filter.preimage.image[j])
					{
						Resources.UnloadAsset(filter_class.preimage.image[j]);
					}
				}
			}
			filter_class.sub_strength_set = false;
			for (count_subfilter = 0; count_subfilter < filter_class.presubfilter.subfilter_index.Count; count_subfilter++)
			{
				subfilter_class subfilter_class = subfilter[filter_class.presubfilter.subfilter_index[count_subfilter]];
				if (erase_deactive)
				{
					if (!subfilter_class.active)
					{
						erase_subfilter(count_subfilter, filter_class.presubfilter);
						count_subfilter--;
						continue;
					}
					erase_deactive_animation_curve(subfilter_class.precurve_list);
					erase_deactive_color_range(subfilter_class.preimage.precolor_range);
				}
				goto IL_063f;
				IL_063f:
				if (fix_database || info_database)
				{
					if (filter_class.presubfilter.subfilter_index[count_subfilter] > subfilter.Count - 1)
					{
						UnityEngine.Debug.Log("Subfilter reference -> " + filter_class.presubfilter.subfilter_index[count_subfilter] + " not found, erasing reference entry...");
						if (!info_database)
						{
							erase_subfilter_reference(filter_class.presubfilter, count_subfilter);
							count_subfilter--;
							continue;
						}
					}
					if (subfilter[filter_class.presubfilter.subfilter_index[count_subfilter]].linked)
					{
						UnityEngine.Debug.Log("Subfilter double linked -> " + filter_class.presubfilter.subfilter_index[count_subfilter]);
						if (fix_database)
						{
							subfilter.Add(new subfilter_class());
							subfilter[subfilter.Count - 1] = copy_subfilter(subfilter[filter_class.presubfilter.subfilter_index[count_subfilter]]);
							filter_class.presubfilter.subfilter_index[count_subfilter] = subfilter.Count - 1;
							continue;
						}
					}
					else
					{
						subfilter[filter_class.presubfilter.subfilter_index[count_subfilter]].linked = true;
						if (filter[prefilter1.filter_index[count_filter]].linked)
						{
							settings.subfilters_linked++;
						}
					}
				}
				if (foldout_subfilter && filter_class.presubfilter.subfilter_index[count_subfilter] == index)
				{
					int num2 = get_layer_description(prelayers[count_prelayer], count_layer);
					if (num2 != -1)
					{
						prelayers[count_prelayer].predescription.description[num2].foldout = true;
					}
					prelayers[count_prelayer].foldout = true;
					prelayers[count_prelayer].layer[count_layer].foldout = true;
					if (call_from == 1)
					{
						prelayers[count_prelayer].layer[count_layer].tree_output.foldout = true;
						prelayers[count_prelayer].layer[count_layer].tree_output.tree[count_tree].foldout = true;
					}
					prefilter1.foldout = true;
					subfilter_class.foldout = true;
					filter_class.foldout = true;
					filter_class.presubfilter.foldout = true;
				}
				if (set_as_default)
				{
					subfilter_class.precurve.set_as_default();
					subfilter_class.prerandom_curve.set_as_default();
				}
				if (close_all_foldout)
				{
					subfilter_class.foldout = false;
				}
				if (check_measure_normal && subfilter_class.active && !measure_normal && subfilter_class.type == condition_type_enum.Direction)
				{
					measure_normal = true;
				}
				if (reset_swap_copy)
				{
					subfilter_class.swap_text = "S";
					subfilter_class.swap_select = false;
					subfilter_class.copy_select = false;
				}
				if (!subfilter_class.active && !loop_inactive)
				{
					continue;
				}
				if (image_auto_scale && subfilter_class.preimage.image_auto_scale && settings.showTerrains)
				{
					if (!prelayers[count_prelayer].prearea.active)
					{
						subfilter_class.preimage.set_image_auto_scale(terrains[0], terrains[0].prearea.area_old, 0);
					}
					else
					{
						subfilter_class.preimage.set_image_auto_scale(terrains[0], prelayers[count_prelayer].prearea.area_old, 0);
					}
				}
				if (subfilter_class.mode == subfilter_mode_enum.strength)
				{
					filter_class.sub_strength_set = true;
				}
				if (store_last_values && subfilter_class.mode != 0 && !current_filter.last_value_declared)
				{
					filter_class.last_value_x = new float[1];
					if (generate_world_mode)
					{
						filter_class.last_value_y = new float[(int)(prelayers[count_prelayer].prearea.area.width / prelayers[count_prelayer].prearea.step.x + 1f)];
					}
					else
					{
						filter_class.last_value_y = new float[(int)(terrains[0].size.x / terrains[0].prearea.step.x + 2f)];
					}
					filter_class.last_pos_x = 4097f;
					filter_class.last_value_declared = true;
				}
				if (!unload_texture)
				{
					continue;
				}
				for (int j = 0; j < subfilter_class.preimage.image.Count; j++)
				{
					if (subfilter_class.preimage.image != null)
					{
						Resources.UnloadAsset(subfilter_class.preimage.image[j]);
					}
				}
				continue;
				IL_061b:
				goto IL_063f;
			}
		}
	}

	public Rect get_terrain_size(int terrain_index)
	{
		Rect result = default(Rect);
		if ((bool)terrains[terrain_index].terrain && (bool)terrains[terrain_index].terrain.terrainData)
		{
			Vector3 size = terrains[terrain_index].terrain.terrainData.size;
			result.width = size.x;
			Vector3 size2 = terrains[terrain_index].terrain.terrainData.size;
			result.height = size2.z;
		}
		return result;
	}

	public Rect get_total_terrain_size()
	{
		Rect result = default(Rect);
		if ((bool)terrains[0].terrain && (bool)terrains[0].terrain.terrainData)
		{
			Vector3 size = terrains[0].terrain.terrainData.size;
			result.width = size.x * terrains[0].tiles.x;
			Vector3 size2 = terrains[0].terrain.terrainData.size;
			result.height = size2.z * terrains[0].tiles.y;
		}
		return result;
	}

	public void loop_prefilter_index(prefilter_class prefilter1, int index)
	{
		for (int i = 0; i < prefilter1.filter_index.Count; i++)
		{
			if (filter[prefilter1.filter_index[i]].type != condition_type_enum.Image || filter[prefilter1.filter_index[i]].preimage.select_mode != select_mode_enum.select)
			{
				continue;
			}
			for (int j = 0; j < filter[prefilter1.filter_index[i]].preimage.precolor_range.color_range.Count; j++)
			{
				if (filter[prefilter1.filter_index[i]].preimage.precolor_range.color_range[j].select_output == index)
				{
					filter[prefilter1.filter_index[i]].preimage.precolor_range.erase_color_range(j);
					j--;
				}
				else if (filter[prefilter1.filter_index[i]].preimage.precolor_range.color_range[j].select_output > index)
				{
					filter[prefilter1.filter_index[i]].preimage.precolor_range.color_range[j].select_output = index;
				}
			}
		}
	}

	public void disable_prefilter_select_mode(prefilter_class prefilter1)
	{
		for (int i = 0; i < prefilter1.filter_index.Count; i++)
		{
			filter[prefilter1.filter_index[i]].preimage.select_mode = select_mode_enum.free;
		}
	}

	public void link_placed_reference()
	{
		if (!script_base)
		{
			return;
		}
		int num = default(int);
		int num2 = default(int);
		int num3 = default(int);
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (num = 0; num < prelayers[i].layer.Count; num++)
			{
				if (!prelayers[i].layer[num].active)
				{
					continue;
				}
				if (prelayers[i].layer[num].output == layer_output_enum.tree)
				{
					prelayers[i].layer[num].tree_output.placed = 0;
					prelayers[i].layer[num].tree_output.placed_reference = script_base.prelayers[i].layer[num].tree_output;
					for (num2 = 0; num2 < prelayers[i].layer[num].tree_output.tree.Count; num2++)
					{
						prelayers[i].layer[num].tree_output.tree[num2].placed = 0;
						prelayers[i].layer[num].tree_output.tree[num2].placed_reference = script_base.prelayers[i].layer[num].tree_output.tree[num2];
					}
				}
				if (prelayers[i].layer[num].output != layer_output_enum.@object)
				{
					continue;
				}
				prelayers[i].layer[num].object_output.placed = 0;
				prelayers[i].layer[num].object_output.placed_reference = script_base.prelayers[i].layer[num].object_output;
				if (prelayers[i].layer[num].object_output.object_mode == object_mode_enum.LinePlacement)
				{
					script_base.prelayers[i].layer[num].object_output.line_placement.line_list[0].points.Clear();
					for (int j = 0; j < prelayers[i].layer[num].object_output.line_placement.line_list[0].point_length; j++)
					{
						script_base.prelayers[i].layer[num].object_output.line_placement.line_list[0].points.Add(new Vector3(0f, 0f, 0f));
					}
					if (prelayers[i].layer[num].object_output.line_placement.preimage.image_auto_scale && settings.showTerrains)
					{
						if (!generate_world_mode && i < 1)
						{
							prelayers[i].layer[num].object_output.line_placement.preimage.set_image_auto_scale(terrains[0], terrains[0].prearea.area_old, 0);
						}
						else
						{
							prelayers[i].layer[num].object_output.line_placement.preimage.set_image_auto_scale(terrains[0], prelayers[i].prearea.area_old, 0);
						}
					}
					line_output = true;
				}
				for (num3 = 0; num3 < prelayers[i].layer[num].object_output.@object.Count; num3++)
				{
					prelayers[i].layer[num].object_output.@object[num3].placed = 0;
					prelayers[i].layer[num].object_output.@object[num3].placed_reference = script_base.prelayers[i].layer[num].object_output.@object[num3];
				}
			}
		}
	}

	public void erase_deactive_color_range(precolor_range_class precolor_range)
	{
		for (int i = 0; i < precolor_range.color_range.Count; i++)
		{
			if (!precolor_range.color_range_value.active[i])
			{
				precolor_range.erase_color_range(i);
				i--;
			}
		}
	}

	public void erase_deactive_animation_curve(List<animation_curve_class> precurve_list)
	{
		for (int i = 0; i < precurve_list.Count; i++)
		{
			if (!precurve_list[i].active)
			{
				erase_animation_curve(precurve_list, i);
				i--;
			}
		}
	}

	public void clear_parent_object(object_class current_object1)
	{
		Transform transform = null;
		if (settings.parentObjectsTerrain)
		{
			for (int i = 0; i < terrains.Count; i++)
			{
				for (int j = 0; j < terrains[i].terrain.transform.childCount; j++)
				{
					transform = terrains[i].terrain.transform.GetChild(j);
					if (transform.name == "Objects")
					{
						UnityEngine.Object.DestroyImmediate(transform.gameObject);
						j--;
					}
				}
			}
			return;
		}
		Transform parent = current_object1.parent;
		if (!parent || !current_object1.parent_clear)
		{
			return;
		}
		int instanceID = parent.gameObject.GetInstanceID();
		Transform[] componentsInChildren = parent.GetComponentsInChildren<Transform>(includeInactive: true);
		if (componentsInChildren == null)
		{
			return;
		}
		IEnumerator enumerator = componentsInChildren.GetEnumerator();
		while (enumerator.MoveNext())
		{
			object obj = enumerator.Current;
			if (!(obj is Transform))
			{
				obj = RuntimeServices.Coerce(obj, typeof(Transform));
			}
			transform = (Transform)obj;
			if ((bool)transform && transform.gameObject.GetInstanceID() != instanceID)
			{
				UnityEngine.Object.DestroyImmediate(transform.gameObject);
			}
		}
	}

	public void unload_textures1()
	{
		int num = default(int);
		for (int i = 0; i < filter.Count; i++)
		{
			for (num = 0; num < filter[i].preimage.image.Count; num++)
			{
				if ((bool)filter[i].preimage.image[num])
				{
					Resources.UnloadAsset(filter[i].preimage.image[num]);
				}
			}
		}
		for (int j = 0; j < subfilter.Count; j++)
		{
			for (num = 0; num < subfilter[j].preimage.image.Count; num++)
			{
				if ((bool)subfilter[j].preimage.image[num])
				{
					Resources.UnloadAsset(subfilter[j].preimage.image[num]);
				}
			}
		}
		if (!settings.showTerrains)
		{
			return;
		}
		for (int k = 0; k < terrains.Count; k++)
		{
			if (terrains[k].terrain.terrainData.splatPrototypes.Length <= 0)
			{
				continue;
			}
			for (int l = 0; l < terrains[k].splat_alpha.Length; l++)
			{
				if ((bool)terrains[k].splat_alpha[l])
				{
					terrains[k].splat_alpha[l] = null;
				}
			}
		}
	}

	public void loop_layer(layer_class layer, int command)
	{
		for (int i = 0; i < layer.object_output.@object.Count; i++)
		{
			if (!layer.object_output.@object[i].prelayer_created)
			{
				continue;
			}
			switch (command)
			{
			case 1:
			{
				add_prelayer(search_level: false);
				int num = prelayers.Count - 1;
				prelayers[num] = copy_prelayer(prelayers[layer.object_output.@object[i].prelayer_index], true);
				layer.object_output.@object[i].prelayer_index = num;
				prelayers[num].index = num;
				prelayers[num].set_prelayer_text();
				for (int j = 0; j < prelayers[num].layer.Count; j++)
				{
					loop_layer(prelayers[num].layer[j], 1);
				}
				break;
			}
			case -1:
				erase_prelayer(layer.object_output.@object[i].prelayer_index);
				break;
			}
		}
	}

	public void loop_object_copy(object_class @object)
	{
		if (@object.prelayer_created)
		{
			for (int i = 0; i < prelayers[@object.prelayer_index].layer.Count; i++)
			{
				loop_layer_copy(prelayers[@object.prelayer_index].layer[i]);
			}
		}
	}

	public void loop_layer_copy(layer_class layer)
	{
		for (int i = 0; i < layer.object_output.@object.Count; i++)
		{
			layer.object_output.@object[i].swap_select = false;
			layer.object_output.@object[i].copy_select = false;
			layer.object_output.@object[i].swap_text = "S";
			layer.object_output.@object[i].placed = 0;
			layer.object_output.placed = 0;
			if (layer.object_output.@object[i].prelayer_created)
			{
				int prelayer_index = layer.object_output.@object[i].prelayer_index;
				for (int j = 0; j < prelayers[prelayer_index].layer.Count; j++)
				{
					loop_layer_copy(prelayers[prelayer_index].layer[j]);
				}
			}
		}
		int num = default(int);
		for (int k = 0; k < layer.color_output.precolor_range.Count; k++)
		{
			for (num = 0; num < layer.color_output.precolor_range[k].color_range.Count; num++)
			{
				layer.color_output.precolor_range[k].color_range[num].swap_select = false;
				layer.color_output.precolor_range[k].color_range[num].copy_select = false;
				layer.color_output.precolor_range[k].color_range[num].swap_text = "S";
			}
		}
		for (int l = 0; l < layer.tree_output.tree.Count; l++)
		{
			layer.tree_output.tree[l].swap_select = false;
			layer.tree_output.tree[l].copy_select = false;
			layer.tree_output.tree[l].swap_text = "S";
			layer.tree_output.placed = 0;
			layer.tree_output.tree[l].placed = 0;
			layer.tree_output.tree[l].placed = 0;
		}
		layer.swap_select = false;
		layer.copy_select = false;
		layer.swap_text = "S";
	}

	public int check_object_rotate(List<Vector3> objects_placed, List<Vector3> objects_placed_rot, Vector3 position, int min_distance_rot_x, int min_distance_rot_z)
	{
		Vector3 vector = default(Vector3);
		int num = 0;
		int result;
		while (true)
		{
			if (num < objects_placed.Count)
			{
				vector = position - objects_placed[num];
				if (!(Mathf.Abs(vector.x) > (float)min_distance_rot_x) && !(Mathf.Abs(vector.z) > (float)min_distance_rot_z))
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public bool check_object_distance(List<distance_class> object_placed_list)
	{
		float num = default(float);
		float num2 = default(float);
		int num3 = object_placed_list.Count - 1;
		int result;
		while (true)
		{
			if (num3 >= 0)
			{
				num = Vector3.Distance(object_info.position, object_placed_list[num3].position);
				num2 = object_placed_list[num3].position.z - object_info.position.z;
				if (!(num >= object_info.min_distance.x) && !(num >= object_placed_list[num3].min_distance.x))
				{
					result = 0;
					break;
				}
				num3--;
				continue;
			}
			object_placed_list.Add(new distance_class());
			object_placed_list[object_placed_list.Count - 1].position = object_info.position;
			object_placed_list[object_placed_list.Count - 1].rotation = object_info.rotation;
			object_placed_list[object_placed_list.Count - 1].min_distance = object_info.min_distance;
			object_placed_list[object_placed_list.Count - 1].min_distance_rotation_group = object_info.min_distance_rotation_group;
			object_placed_list[object_placed_list.Count - 1].distance_rotation = object_info.distance_rotation;
			object_placed_list[object_placed_list.Count - 1].distance_mode = object_info.distance_mode;
			object_placed_list[object_placed_list.Count - 1].rotation_group = object_info.rotation_group;
			result = 1;
			break;
		}
		return (byte)result != 0;
	}

	public void relink_subfilter_index(int subfilter_index)
	{
		for (int i = 0; i < filter.Count; i++)
		{
			for (int j = 0; j < filter[i].presubfilter.subfilter_index.Count; j++)
			{
				if (filter[i].presubfilter.subfilter_index[j] == subfilter.Count)
				{
					filter[i].presubfilter.subfilter_index[j] = subfilter_index;
					return;
				}
			}
		}
	}

	public void relink_filter_index(int filter_index)
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				for (int k = 0; k < prelayers[i].layer[j].prefilter.filter_index.Count; k++)
				{
					if (prelayers[i].layer[j].prefilter.filter_index[k] == filter.Count)
					{
						prelayers[i].layer[j].prefilter.filter_index[k] = filter_index;
						return;
					}
				}
				for (int l = 0; l < prelayers[i].layer[j].tree_output.tree.Count; l++)
				{
					for (int k = 0; k < prelayers[i].layer[j].tree_output.tree[l].prefilter.filter_index.Count; k++)
					{
						if (prelayers[i].layer[j].tree_output.tree[l].prefilter.filter_index[k] == filter.Count)
						{
							prelayers[i].layer[j].tree_output.tree[l].prefilter.filter_index[k] = filter_index;
							return;
						}
					}
				}
			}
		}
	}

	public bool search_filter_index(int filter_index)
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < prelayers.Count)
			{
				for (int i = 0; i < prelayers[num].layer.Count; i++)
				{
					int num2 = 0;
					while (num2 < prelayers[num].layer[i].prefilter.filter_index.Count)
					{
						if (prelayers[num].layer[i].prefilter.filter_index[num2] != filter_index)
						{
							num2++;
							continue;
						}
						goto IL_0042;
					}
					for (int j = 0; j < prelayers[num].layer[i].tree_output.tree.Count; j++)
					{
						num2 = 0;
						while (num2 < prelayers[num].layer[i].tree_output.tree[j].prefilter.filter_index.Count)
						{
							if (prelayers[num].layer[i].tree_output.tree[j].prefilter.filter_index[num2] != filter_index)
							{
								num2++;
								continue;
							}
							goto IL_00d5;
						}
					}
				}
				num++;
				continue;
			}
			result = 0;
			break;
			IL_00d5:
			filter[filter_index].linked = true;
			result = 1;
			break;
			IL_0042:
			filter[filter_index].linked = true;
			result = 1;
			break;
		}
		return (byte)result != 0;
	}

	public bool search_subfilter_index(int subfilter_index)
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < filter.Count)
			{
				int num2 = 0;
				while (num2 < filter[num].presubfilter.subfilter_index.Count)
				{
					if (filter[num].presubfilter.subfilter_index[num2] != subfilter_index)
					{
						num2++;
						continue;
					}
					goto IL_0030;
				}
				num++;
				continue;
			}
			result = 0;
			break;
			IL_0030:
			subfilter[subfilter_index].linked = true;
			result = 1;
			break;
		}
		return (byte)result != 0;
	}

	public void reset_link_prelayer()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			prelayers[i].linked = false;
		}
	}

	public void reset_link_filter()
	{
		for (int i = 0; i < filter.Count; i++)
		{
			filter[i].linked = false;
		}
	}

	public void reset_link_subfilter()
	{
		for (int i = 0; i < subfilter.Count; i++)
		{
			subfilter[i].linked = false;
		}
	}

	public void erase_unlinked_prelayer(bool erase)
	{
		for (int i = 1; i < prelayers.Count; i++)
		{
			if (!prelayers[i].linked)
			{
				if (erase)
				{
					UnityEngine.Debug.Log("Erasing unlinked Prelayer -> " + i);
					erase_prelayer(i);
					i--;
				}
				else
				{
					UnityEngine.Debug.Log("Unlinked Prelayer -> " + i);
				}
			}
		}
	}

	public void erase_unlinked_filter(bool erase)
	{
		for (int i = 0; i < filter.Count; i++)
		{
			if (!filter[i].linked)
			{
				if (erase)
				{
					UnityEngine.Debug.Log("Erasing unlinked Filter -> " + i);
					erase_filter_unlinked(i);
					i--;
				}
				else
				{
					UnityEngine.Debug.Log("Unlinked Filter -> " + i);
				}
			}
		}
	}

	public void erase_unlinked_subfilter(bool erase)
	{
		for (int i = 0; i < subfilter.Count; i++)
		{
			if (!subfilter[i].linked)
			{
				if (erase)
				{
					UnityEngine.Debug.Log("Erasing unlinked Subfilter -> " + i);
					erase_subfilter_unlinked(i);
					i--;
				}
				else
				{
					UnityEngine.Debug.Log("Unlinked subfilter -> " + i);
				}
			}
		}
	}

	public void select_image_prelayer()
	{
		filter_class filter_class = null;
		for (int i = 0; i < prelayer.layer.Count; i++)
		{
			for (int j = 0; j < prelayer.layer[i].prefilter.filter_index.Count; j++)
			{
				filter_class = filter[prelayer.layer[i].prefilter.filter_index[j]];
				select_image_filter(filter_class);
				select_image_subfilter(filter_class);
			}
			if (prelayer.layer[i].output != layer_output_enum.tree)
			{
				continue;
			}
			for (int k = 0; k < prelayer.layer[i].tree_output.tree.Count; k++)
			{
				for (int j = 0; j < prelayer.layer[i].tree_output.tree[k].prefilter.filter_index.Count; j++)
				{
					filter_class = filter[prelayer.layer[i].tree_output.tree[k].prefilter.filter_index[j]];
					select_image_filter(filter_class);
					select_image_subfilter(filter_class);
				}
			}
		}
	}

	public void select_image_filter(filter_class current_filter1)
	{
		if (current_filter1.type == condition_type_enum.Image && current_filter1.preimage.image_list_mode == list_condition_enum.Random)
		{
			current_filter1.preimage.image_number = UnityEngine.Random.Range(0, current_filter1.preimage.image.Count - 1);
		}
	}

	public void select_image_subfilter(filter_class current_filter1)
	{
		subfilter_class subfilter_class = null;
		for (int i = 0; i < current_filter1.presubfilter.subfilter_index.Count; i++)
		{
			subfilter_class = subfilter[current_filter1.presubfilter.subfilter_index[i]];
			if (subfilter_class.type == condition_type_enum.Image && subfilter_class.preimage.image_list_mode == list_condition_enum.Random)
			{
				subfilter_class.preimage.image_number = UnityEngine.Random.Range(0, subfilter_class.preimage.image.Count - 1);
			}
		}
	}

	public int search_filter_swap()
	{
		int num = default(int);
		int result;
		while (true)
		{
			if (num < filter.Count)
			{
				if (filter[num].swap_select)
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public int search_filter_copy()
	{
		int num = default(int);
		int result;
		while (true)
		{
			if (num < filter.Count)
			{
				if (filter[num].copy_select)
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public int search_subfilter_swap()
	{
		int num = default(int);
		int result;
		while (true)
		{
			if (num < subfilter.Count)
			{
				if (subfilter[num].swap_select)
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public int search_subfilter_copy()
	{
		int num = default(int);
		int result;
		while (true)
		{
			if (num < subfilter.Count)
			{
				if (subfilter[num].copy_select)
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			copy_subfilter_select = false;
			result = -1;
			break;
		}
		return result;
	}

	public void search_layer_swap()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				if (prelayers[i].layer[j].swap_select)
				{
					swap_prelayer_index = i;
					swap_layer_index = j;
					return;
				}
			}
		}
	}

	public void search_layer_copy()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				if (prelayers[i].layer[j].copy_select)
				{
					copy_prelayer_index = i;
					copy_layer_index = j;
					return;
				}
			}
		}
	}

	public void search_description_swap()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].predescription.description.Count; j++)
			{
				if (prelayers[i].predescription.description[j].swap_select)
				{
					swap_description_prelayer_index = i;
					swap_description_position = j;
					return;
				}
			}
		}
	}

	public void search_description_copy()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].predescription.description.Count; j++)
			{
				if (prelayers[i].predescription.description[j].copy_select)
				{
					copy_description_prelayer_index = i;
					copy_description_position = j;
					return;
				}
			}
		}
	}

	public void search_object_swap()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				for (int k = 0; k < prelayers[i].layer[j].object_output.@object.Count; k++)
				{
					if (prelayers[i].layer[j].object_output.@object[k].swap_select)
					{
						swap_object_output = prelayers[i].layer[j].object_output;
						swap_object_number = k;
						return;
					}
				}
			}
		}
	}

	public object_class search_object_copy()
	{
		int num = 0;
		object result;
		while (true)
		{
			int i;
			int num2;
			if (num < prelayers.Count)
			{
				for (i = 0; i < prelayers[num].layer.Count; i++)
				{
					num2 = 0;
					while (num2 < prelayers[num].layer[i].object_output.@object.Count)
					{
						if (!prelayers[num].layer[i].object_output.@object[num2].copy_select)
						{
							num2++;
							continue;
						}
						goto IL_0046;
					}
				}
				num++;
				continue;
			}
			result = new object_class();
			break;
			IL_0046:
			result = prelayers[num].layer[i].object_output.@object[num2];
			break;
		}
		return (object_class)result;
	}

	public void search_tree_swap()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				for (int k = 0; k < prelayers[i].layer[j].tree_output.tree.Count; k++)
				{
					if (prelayers[i].layer[j].tree_output.tree[k].swap_select)
					{
						swap_tree_output = prelayers[i].layer[j].tree_output;
						swap_tree_position = k;
						return;
					}
				}
			}
		}
	}

	public tree_class search_tree_copy()
	{
		int num = 0;
		object result;
		while (true)
		{
			int i;
			int num2;
			if (num < prelayers.Count)
			{
				for (i = 0; i < prelayers[num].layer.Count; i++)
				{
					num2 = 0;
					while (num2 < prelayers[num].layer[i].tree_output.tree.Count)
					{
						if (!prelayers[num].layer[i].tree_output.tree[num2].copy_select)
						{
							num2++;
							continue;
						}
						goto IL_0046;
					}
				}
				num++;
				continue;
			}
			result = new tree_class(script, new_filter: false);
			break;
			IL_0046:
			result = prelayers[num].layer[i].tree_output.tree[num2];
			break;
		}
		return (tree_class)result;
	}

	public void search_color_range_swap()
	{
		int num = default(int);
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				for (int k = 0; k < prelayers[i].layer[j].color_output.precolor_range.Count; k++)
				{
					for (num = 0; num < prelayers[i].layer[j].color_output.precolor_range[k].color_range.Count; num++)
					{
						if (prelayers[i].layer[j].color_output.precolor_range[k].color_range[num].swap_select)
						{
							swap_precolor_range = prelayers[i].layer[j].color_output.precolor_range[k];
							swap_color_range_number = num;
							return;
						}
					}
				}
				for (int l = 0; l < prelayers[i].layer[j].tree_output.tree.Count; l++)
				{
					for (num = 0; num < prelayers[i].layer[j].tree_output.tree[l].precolor_range.color_range.Count; num++)
					{
						if (prelayers[i].layer[j].tree_output.tree[l].precolor_range.color_range[num].swap_select)
						{
							swap_precolor_range = prelayers[i].layer[j].tree_output.tree[l].precolor_range;
							swap_color_range_number = num;
							return;
						}
					}
				}
			}
		}
		for (int m = 0; m < filter.Count; m++)
		{
			for (num = 0; num < filter[m].preimage.precolor_range.color_range.Count; num++)
			{
				if (filter[m].preimage.precolor_range.color_range[num].swap_select)
				{
					swap_precolor_range = filter[m].preimage.precolor_range;
					swap_color_range_number = num;
					return;
				}
			}
		}
		for (int n = 0; n < subfilter.Count; n++)
		{
			for (num = 0; num < subfilter[n].preimage.precolor_range.color_range.Count; num++)
			{
				if (subfilter[n].preimage.precolor_range.color_range[num].swap_select)
				{
					swap_precolor_range = subfilter[n].preimage.precolor_range;
					swap_color_range_number = num;
					return;
				}
			}
		}
		for (int num2 = 0; num2 < pattern_tool.patterns.Count; num2++)
		{
			for (num = 0; num < pattern_tool.patterns[num2].precolor_range.color_range.Count; num++)
			{
				if (pattern_tool.patterns[num2].precolor_range.color_range[num].swap_select)
				{
					swap_precolor_range = pattern_tool.patterns[num2].precolor_range;
					swap_color_range_number = num;
					return;
				}
			}
		}
		num = 0;
		while (true)
		{
			if (num < texture_tool.precolor_range.color_range.Count)
			{
				if (texture_tool.precolor_range.color_range[num].swap_select)
				{
					break;
				}
				num++;
				continue;
			}
			return;
		}
		swap_precolor_range = texture_tool.precolor_range;
		swap_color_range_number = num;
	}

	public color_range_class search_color_range_copy()
	{
		int num = default(int);
		int num2 = 0;
		object result;
		while (true)
		{
			int i;
			int j;
			int k;
			if (num2 < prelayers.Count)
			{
				for (i = 0; i < prelayers[num2].layer.Count; i++)
				{
					for (j = 0; j < prelayers[num2].layer[i].color_output.precolor_range.Count; j++)
					{
						num = 0;
						while (num < prelayers[num2].layer[i].color_output.precolor_range[j].color_range.Count)
						{
							if (!prelayers[num2].layer[i].color_output.precolor_range[j].color_range[num].copy_select)
							{
								num++;
								continue;
							}
							goto IL_0060;
						}
					}
					for (k = 0; k < prelayers[num2].layer[i].tree_output.tree.Count; k++)
					{
						num = 0;
						while (num < prelayers[num2].layer[i].tree_output.tree[k].precolor_range.color_range.Count)
						{
							if (!prelayers[num2].layer[i].tree_output.tree[k].precolor_range.color_range[num].copy_select)
							{
								num++;
								continue;
							}
							goto IL_0153;
						}
					}
				}
				num2++;
				continue;
			}
			int num3 = 0;
			while (true)
			{
				if (num3 < filter.Count)
				{
					num = 0;
					while (num < filter[num3].preimage.precolor_range.color_range.Count)
					{
						if (!filter[num3].preimage.precolor_range.color_range[num].copy_select)
						{
							num++;
							continue;
						}
						goto IL_0274;
					}
					num3++;
					continue;
				}
				int num4 = 0;
				while (true)
				{
					if (num4 < subfilter.Count)
					{
						num = 0;
						while (num < subfilter[num4].preimage.precolor_range.color_range.Count)
						{
							if (!subfilter[num4].preimage.precolor_range.color_range[num].copy_select)
							{
								num++;
								continue;
							}
							goto IL_0319;
						}
						num4++;
						continue;
					}
					int num5 = 0;
					while (true)
					{
						if (num5 < pattern_tool.patterns.Count)
						{
							num = 0;
							while (num < pattern_tool.patterns[num5].precolor_range.color_range.Count)
							{
								if (!pattern_tool.patterns[num5].precolor_range.color_range[num].copy_select)
								{
									num++;
									continue;
								}
								goto IL_03be;
							}
							num5++;
							continue;
						}
						num = 0;
						while (true)
						{
							if (num < texture_tool.precolor_range.color_range.Count)
							{
								if (texture_tool.precolor_range.color_range[num].copy_select)
								{
									result = texture_tool.precolor_range.color_range[num];
									break;
								}
								num++;
								continue;
							}
							result = new color_range_class();
							break;
						}
						break;
						IL_03be:
						result = pattern_tool.patterns[num5].precolor_range.color_range[num];
						break;
					}
					break;
					IL_0319:
					result = subfilter[num4].preimage.precolor_range.color_range[num];
					break;
				}
				break;
				IL_0274:
				result = filter[num3].preimage.precolor_range.color_range[num];
				break;
			}
			break;
			IL_0153:
			result = prelayers[num2].layer[i].tree_output.tree[k].precolor_range.color_range[num];
			break;
			IL_0060:
			result = prelayers[num2].layer[i].color_output.precolor_range[j].color_range[num];
			break;
		}
		return (color_range_class)result;
	}

	public int get_import_resolution_to_list(int resolution)
	{
		int result = -1;
		switch (resolution)
		{
		case 32:
			result = 0;
			break;
		case 64:
			result = 1;
			break;
		case 128:
			result = 2;
			break;
		case 256:
			result = 3;
			break;
		case 512:
			result = 4;
			break;
		case 1024:
			result = 5;
			break;
		case 2048:
			result = 6;
			break;
		case 4096:
			result = 7;
			break;
		}
		return result;
	}

	public int set_import_resolution_from_list(int resolution_index)
	{
		int result = -1;
		switch (resolution_index)
		{
		case 0:
			result = 32;
			break;
		case 1:
			result = 64;
			break;
		case 2:
			result = 128;
			break;
		case 3:
			result = 256;
			break;
		case 4:
			result = 512;
			break;
		case 5:
			result = 1024;
			break;
		case 6:
			result = 2048;
			break;
		case 7:
			result = 4096;
			break;
		}
		return result;
	}

	public void get_terrain_resolution_to_list(terrain_class preterrain1)
	{
		if (preterrain1.heightmap_resolution == 4097f)
		{
			preterrain1.heightmap_resolution_list = 0;
		}
		else if (preterrain1.heightmap_resolution == 2049f)
		{
			preterrain1.heightmap_resolution_list = 1;
		}
		else if (preterrain1.heightmap_resolution == 1025f)
		{
			preterrain1.heightmap_resolution_list = 2;
		}
		else if (preterrain1.heightmap_resolution == 513f)
		{
			preterrain1.heightmap_resolution_list = 3;
		}
		else if (preterrain1.heightmap_resolution == 257f)
		{
			preterrain1.heightmap_resolution_list = 4;
		}
		else if (preterrain1.heightmap_resolution == 129f)
		{
			preterrain1.heightmap_resolution_list = 5;
		}
		else if (preterrain1.heightmap_resolution == 65f)
		{
			preterrain1.heightmap_resolution_list = 6;
		}
		else if (preterrain1.heightmap_resolution == 33f)
		{
			preterrain1.heightmap_resolution_list = 7;
		}
		if (preterrain1.splatmap_resolution == 2048f)
		{
			preterrain1.splatmap_resolution_list = 0;
		}
		else if (preterrain1.splatmap_resolution == 1024f)
		{
			preterrain1.splatmap_resolution_list = 1;
		}
		else if (preterrain1.splatmap_resolution == 512f)
		{
			preterrain1.splatmap_resolution_list = 2;
		}
		else if (preterrain1.splatmap_resolution == 256f)
		{
			preterrain1.splatmap_resolution_list = 3;
		}
		else if (preterrain1.splatmap_resolution == 128f)
		{
			preterrain1.splatmap_resolution_list = 4;
		}
		else if (preterrain1.splatmap_resolution == 64f)
		{
			preterrain1.splatmap_resolution_list = 5;
		}
		else if (preterrain1.splatmap_resolution == 32f)
		{
			preterrain1.splatmap_resolution_list = 6;
		}
		else if (preterrain1.splatmap_resolution == 16f)
		{
			preterrain1.splatmap_resolution_list = 7;
		}
		if (preterrain1.basemap_resolution == 2048f)
		{
			preterrain1.basemap_resolution_list = 0;
		}
		else if (preterrain1.basemap_resolution == 1024f)
		{
			preterrain1.basemap_resolution_list = 1;
		}
		else if (preterrain1.basemap_resolution == 512f)
		{
			preterrain1.basemap_resolution_list = 2;
		}
		else if (preterrain1.basemap_resolution == 256f)
		{
			preterrain1.basemap_resolution_list = 3;
		}
		else if (preterrain1.basemap_resolution == 128f)
		{
			preterrain1.basemap_resolution_list = 4;
		}
		else if (preterrain1.basemap_resolution == 64f)
		{
			preterrain1.basemap_resolution_list = 5;
		}
		else if (preterrain1.basemap_resolution == 32f)
		{
			preterrain1.basemap_resolution_list = 6;
		}
		else if (preterrain1.basemap_resolution == 16f)
		{
			preterrain1.basemap_resolution_list = 7;
		}
		if (preterrain1.detail_resolution_per_patch == 128f)
		{
			preterrain1.detail_resolution_per_patch_list = 4;
		}
		else if (preterrain1.detail_resolution_per_patch == 64f)
		{
			preterrain1.detail_resolution_per_patch_list = 3;
		}
		else if (preterrain1.detail_resolution_per_patch == 32f)
		{
			preterrain1.detail_resolution_per_patch_list = 2;
		}
		else if (preterrain1.detail_resolution_per_patch == 16f)
		{
			preterrain1.detail_resolution_per_patch_list = 1;
		}
		else if (preterrain1.detail_resolution_per_patch == 8f)
		{
			preterrain1.detail_resolution_per_patch_list = 0;
		}
	}

	public void set_terrain_resolution_from_list(terrain_class preterrain1)
	{
		if (preterrain1.heightmap_resolution_list == 0)
		{
			preterrain1.heightmap_resolution = 4097f;
		}
		else if (preterrain1.heightmap_resolution_list == 1)
		{
			preterrain1.heightmap_resolution = 2049f;
		}
		else if (preterrain1.heightmap_resolution_list == 2)
		{
			preterrain1.heightmap_resolution = 1025f;
		}
		else if (preterrain1.heightmap_resolution_list == 3)
		{
			preterrain1.heightmap_resolution = 513f;
		}
		else if (preterrain1.heightmap_resolution_list == 4)
		{
			preterrain1.heightmap_resolution = 257f;
		}
		else if (preterrain1.heightmap_resolution_list == 5)
		{
			preterrain1.heightmap_resolution = 129f;
		}
		else if (preterrain1.heightmap_resolution_list == 6)
		{
			preterrain1.heightmap_resolution = 65f;
		}
		else if (preterrain1.heightmap_resolution_list == 7)
		{
			preterrain1.heightmap_resolution = 33f;
		}
		if (preterrain1.splatmap_resolution_list == 0)
		{
			preterrain1.splatmap_resolution = 2048f;
		}
		else if (preterrain1.splatmap_resolution_list == 1)
		{
			preterrain1.splatmap_resolution = 1024f;
		}
		else if (preterrain1.splatmap_resolution_list == 2)
		{
			preterrain1.splatmap_resolution = 512f;
		}
		else if (preterrain1.splatmap_resolution_list == 3)
		{
			preterrain1.splatmap_resolution = 256f;
		}
		else if (preterrain1.splatmap_resolution_list == 4)
		{
			preterrain1.splatmap_resolution = 128f;
		}
		else if (preterrain1.splatmap_resolution_list == 5)
		{
			preterrain1.splatmap_resolution = 64f;
		}
		else if (preterrain1.splatmap_resolution_list == 6)
		{
			preterrain1.splatmap_resolution = 32f;
		}
		else if (preterrain1.splatmap_resolution_list == 7)
		{
			preterrain1.splatmap_resolution = 16f;
		}
		if (preterrain1.basemap_resolution_list == 0)
		{
			preterrain1.basemap_resolution = 2048f;
		}
		else if (preterrain1.basemap_resolution_list == 1)
		{
			preterrain1.basemap_resolution = 1024f;
		}
		else if (preterrain1.basemap_resolution_list == 2)
		{
			preterrain1.basemap_resolution = 512f;
		}
		else if (preterrain1.basemap_resolution_list == 3)
		{
			preterrain1.basemap_resolution = 256f;
		}
		else if (preterrain1.basemap_resolution_list == 4)
		{
			preterrain1.basemap_resolution = 128f;
		}
		else if (preterrain1.basemap_resolution_list == 5)
		{
			preterrain1.basemap_resolution = 64f;
		}
		else if (preterrain1.basemap_resolution_list == 6)
		{
			preterrain1.basemap_resolution = 32f;
		}
		else if (preterrain1.basemap_resolution_list == 7)
		{
			preterrain1.basemap_resolution = 16f;
		}
		if (preterrain1.detail_resolution_per_patch_list == 0)
		{
			preterrain1.detail_resolution_per_patch = 8f;
		}
		else if (preterrain1.detail_resolution_per_patch_list == 1)
		{
			preterrain1.detail_resolution_per_patch = 16f;
		}
		else if (preterrain1.detail_resolution_per_patch_list == 2)
		{
			preterrain1.detail_resolution_per_patch = 32f;
		}
		else if (preterrain1.detail_resolution_per_patch_list == 3)
		{
			preterrain1.detail_resolution_per_patch = 64f;
		}
		else if (preterrain1.detail_resolution_per_patch_list == 4)
		{
			preterrain1.detail_resolution_per_patch = 128f;
		}
	}

	public void get_terrains_position()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			ref Rect rect = ref terrains[i].rect;
			Vector3 vector = terrains[i].terrain.transform.position;
			rect.x = vector.x;
			ref Rect rect2 = ref terrains[i].rect;
			Vector3 vector2 = terrains[i].terrain.transform.position;
			rect2.y = vector2.z;
			ref Rect rect3 = ref terrains[i].rect;
			Vector3 size = terrains[i].terrain.terrainData.size;
			rect3.width = size.x;
			ref Rect rect4 = ref terrains[i].rect;
			Vector3 size2 = terrains[i].terrain.terrainData.size;
			rect4.height = size2.z;
		}
		if (slice_tool && (bool)slice_tool_terrain)
		{
			ref Rect reference = ref slice_tool_rect;
			Vector3 vector3 = slice_tool_terrain.transform.position;
			reference.x = vector3.x;
			ref Rect reference2 = ref slice_tool_rect;
			Vector3 vector4 = slice_tool_terrain.transform.position;
			reference2.y = vector4.z;
			ref Rect reference3 = ref slice_tool_rect;
			Vector3 size3 = slice_tool_terrain.terrainData.size;
			reference3.width = size3.x;
			ref Rect reference4 = ref slice_tool_rect;
			Vector3 size4 = slice_tool_terrain.terrainData.size;
			reference4.height = size4.z;
		}
	}

	public void set_basemap_max(bool editor)
	{
		if (terrains.Count > 1)
		{
			if (editor)
			{
				settings.editor_basemap_distance_max = (int)(terrains[0].tiles.x * terrains[0].size.x);
			}
			else
			{
				settings.runtime_basemap_distance_max = (int)(terrains[0].tiles.x * terrains[0].size.x);
			}
		}
		else if (editor)
		{
			settings.editor_basemap_distance_max = (int)terrains[0].size.x;
		}
		else
		{
			settings.runtime_basemap_distance_max = (int)terrains[0].size.x;
		}
	}

	public void get_all_terrain_settings(string command)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			get_terrain_settings(terrains[i], command);
			check_synchronous_terrain_size(terrains[i]);
		}
	}

	public void get_terrain_settings(terrain_class preterrain1, string command)
	{
		if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData)
		{
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			bool flag5 = false;
			bool flag6 = false;
			bool flag7 = false;
			bool flag8 = false;
			if (command.IndexOf("(siz)") != -1)
			{
				flag = true;
			}
			if (command.IndexOf("(res)") != -1)
			{
				flag2 = true;
			}
			if (command.IndexOf("(con)") != -1)
			{
				flag3 = true;
			}
			if (command.IndexOf("(all)") != -1)
			{
				flag4 = true;
			}
			if (command.IndexOf("(fir)") != -1)
			{
				flag5 = true;
			}
			if (command.IndexOf("(spl)") != -1)
			{
				flag6 = true;
			}
			if (command.IndexOf("(tre)") != -1)
			{
				flag7 = true;
			}
			if (command.IndexOf("(gra)") != -1)
			{
				flag8 = true;
			}
			preterrain1.splat_length = preterrain1.terrain.terrainData.splatPrototypes.Length;
			preterrain1.name = preterrain1.terrain.name;
			if (flag || flag4)
			{
				preterrain1.size = preterrain1.terrain.terrainData.size;
				check_synchronous_terrain_size(preterrain1);
				preterrain1.scale.x = preterrain1.size.x / (float)preterrain1.terrain.terrainData.heightmapResolution;
				preterrain1.scale.y = preterrain1.size.y / (float)preterrain1.terrain.terrainData.heightmapResolution;
				preterrain1.scale.z = preterrain1.size.z / (float)preterrain1.terrain.terrainData.heightmapResolution;
			}
			if (flag2 || flag4)
			{
				preterrain1.heightmap_resolution = preterrain1.terrain.terrainData.heightmapResolution;
				preterrain1.splatmap_resolution = preterrain1.terrain.terrainData.alphamapResolution;
				preterrain1.detail_resolution = preterrain1.terrain.terrainData.detailResolution;
				preterrain1.basemap_resolution = preterrain1.terrain.terrainData.baseMapResolution;
				get_terrain_resolution_to_list(preterrain1);
				check_synchronous_terrain_resolutions(preterrain1);
			}
			if (flag3 || flag4)
			{
				ref Vector2 heightmap_conversion = ref preterrain1.heightmap_conversion;
				Vector3 size = preterrain1.terrain.terrainData.size;
				heightmap_conversion.x = size.x / (float)(preterrain1.terrain.terrainData.heightmapResolution - 1);
				ref Vector2 heightmap_conversion2 = ref preterrain1.heightmap_conversion;
				Vector3 size2 = preterrain1.terrain.terrainData.size;
				heightmap_conversion2.y = size2.z / (float)(preterrain1.terrain.terrainData.heightmapResolution - 1);
				ref Vector2 splatmap_conversion = ref preterrain1.splatmap_conversion;
				Vector3 size3 = preterrain1.terrain.terrainData.size;
				splatmap_conversion.x = size3.x / (float)(preterrain1.terrain.terrainData.alphamapResolution - 1);
				ref Vector2 splatmap_conversion2 = ref preterrain1.splatmap_conversion;
				Vector3 size4 = preterrain1.terrain.terrainData.size;
				splatmap_conversion2.y = size4.z / (float)(preterrain1.terrain.terrainData.alphamapResolution - 1);
				ref Vector2 detailmap_conversion = ref preterrain1.detailmap_conversion;
				Vector3 size5 = preterrain1.terrain.terrainData.size;
				detailmap_conversion.x = size5.x / (float)(preterrain1.terrain.terrainData.detailResolution - 1);
				ref Vector2 detailmap_conversion2 = ref preterrain1.detailmap_conversion;
				Vector3 size6 = preterrain1.terrain.terrainData.size;
				detailmap_conversion2.y = size6.z / (float)(preterrain1.terrain.terrainData.detailResolution - 1);
				set_area_resolution(preterrain1, preterrain1.prearea);
			}
			if (flag5)
			{
				area_class prearea = preterrain1.prearea;
				float x = 0f;
				float y = 0f;
				Vector3 size7 = preterrain1.terrain.terrainData.size;
				float x2 = size7.x;
				Vector3 size8 = preterrain1.terrain.terrainData.size;
				prearea.area_max = new Rect(x, y, x2, size8.z);
				preterrain1.prearea.area = preterrain1.prearea.area_max;
				preterrain1.prearea.set_resolution_mode_text();
				get_terrain_parameter_settings(preterrain1);
			}
			if (flag || flag4 || flag3 || flag2 || flag5)
			{
				set_area_resolution(preterrain1, preterrain1.prearea);
				set_area_resolution_prelayers(preterrain1);
			}
			float xMax = preterrain1.prearea.area.xMax;
			Vector3 size9 = preterrain1.terrain.terrainData.size;
			if (!(xMax <= size9.x))
			{
				ref Rect area = ref preterrain1.prearea.area;
				Vector3 size10 = preterrain1.terrain.terrainData.size;
				area.xMax = size10.x;
			}
			float yMax = preterrain1.prearea.area.yMax;
			Vector3 size11 = preterrain1.terrain.terrainData.size;
			if (!(yMax <= size11.y))
			{
				ref Rect area2 = ref preterrain1.prearea.area;
				Vector3 size12 = preterrain1.terrain.terrainData.size;
				area2.yMax = size12.z;
			}
			if (flag6)
			{
				get_terrain_splat_textures(preterrain1);
				check_synchronous_terrain_splat_textures(preterrain1);
			}
			if (flag7)
			{
				get_terrain_trees(preterrain1);
				check_synchronous_terrain_trees(preterrain1);
			}
			if (flag8)
			{
				get_terrain_details(preterrain1);
				check_synchronous_terrain_detail(preterrain1);
			}
		}
	}

	public void set_area_resolution_prelayers(terrain_class preterrain1)
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			set_area_resolution(preterrain1, prelayers[i].prearea);
		}
	}

	public void set_area_resolution(area_class prearea)
	{
		prearea.step.x = object_resolution;
		prearea.step.y = object_resolution;
		prearea.conversion_step = prearea.step;
		prearea.resolution = object_resolution;
	}

	public void set_area_resolution(terrain_class preterrain1, area_class prearea)
	{
		if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData)
		{
			if (prearea.resolution_mode == resolution_mode_enum.Heightmap)
			{
				ref Vector2 step = ref prearea.step;
				Vector3 size = preterrain1.terrain.terrainData.size;
				step.x = size.x / (float)(preterrain1.terrain.terrainData.heightmapResolution - 1);
				ref Vector2 step2 = ref prearea.step;
				Vector3 size2 = preterrain1.terrain.terrainData.size;
				step2.y = size2.z / (float)(preterrain1.terrain.terrainData.heightmapResolution - 1);
				prearea.conversion_step = prearea.step;
				prearea.resolution = preterrain1.heightmap_resolution;
			}
			else if (prearea.resolution_mode == resolution_mode_enum.Colormap)
			{
				ref Vector2 step3 = ref prearea.step;
				Vector3 size3 = preterrain1.terrain.terrainData.size;
				step3.x = size3.x / (float)colormap_resolution;
				ref Vector2 step4 = ref prearea.step;
				Vector3 size4 = preterrain1.terrain.terrainData.size;
				step4.y = size4.z / (float)colormap_resolution;
				ref Vector2 splatmap_conversion = ref preterrain1.splatmap_conversion;
				Vector3 size5 = preterrain1.terrain.terrainData.size;
				splatmap_conversion.x = size5.x / (float)(colormap_resolution - 1);
				ref Vector2 splatmap_conversion2 = ref preterrain1.splatmap_conversion;
				Vector3 size6 = preterrain1.terrain.terrainData.size;
				splatmap_conversion2.y = size6.z / (float)(colormap_resolution - 1);
				preterrain1.splatmap_resolution = colormap_resolution;
				prearea.conversion_step = prearea.step;
				prearea.resolution = colormap_resolution;
			}
			else if (prearea.resolution_mode == resolution_mode_enum.Splatmap)
			{
				ref Vector2 step5 = ref prearea.step;
				Vector3 size7 = preterrain1.terrain.terrainData.size;
				step5.x = size7.x / (float)preterrain1.terrain.terrainData.alphamapResolution;
				ref Vector2 step6 = ref prearea.step;
				Vector3 size8 = preterrain1.terrain.terrainData.size;
				step6.y = size8.z / (float)preterrain1.terrain.terrainData.alphamapResolution;
				prearea.conversion_step = prearea.step;
				prearea.resolution = preterrain1.splatmap_resolution;
			}
			else if (prearea.resolution_mode == resolution_mode_enum.Detailmap)
			{
				ref Vector2 step7 = ref prearea.step;
				Vector3 size9 = preterrain1.terrain.terrainData.size;
				step7.x = size9.x / (float)preterrain1.terrain.terrainData.detailResolution;
				ref Vector2 step8 = ref prearea.step;
				Vector3 size10 = preterrain1.terrain.terrainData.size;
				step8.y = size10.z / (float)preterrain1.terrain.terrainData.detailResolution;
				prearea.conversion_step = prearea.step;
				prearea.resolution = preterrain1.detail_resolution;
			}
			else if (prearea.resolution_mode == resolution_mode_enum.Tree)
			{
				ref Vector2 step9 = ref prearea.step;
				Vector3 size11 = preterrain1.terrain.terrainData.size;
				step9.x = size11.x / (float)prearea.tree_resolution;
				ref Vector2 step10 = ref prearea.step;
				Vector3 size12 = preterrain1.terrain.terrainData.size;
				step10.y = size12.z / (float)prearea.tree_resolution;
				prearea.conversion_step = prearea.step;
				prearea.resolution = prearea.tree_resolution;
			}
			else if (prearea.resolution_mode == resolution_mode_enum.Object)
			{
				ref Vector2 step11 = ref prearea.step;
				Vector3 size13 = preterrain1.terrain.terrainData.size;
				step11.x = size13.x / (float)prearea.object_resolution;
				ref Vector2 step12 = ref prearea.step;
				Vector3 size14 = preterrain1.terrain.terrainData.size;
				step12.y = size14.z / (float)prearea.object_resolution;
				prearea.conversion_step = prearea.step;
				prearea.resolution = prearea.object_resolution;
			}
			else if (prearea.resolution_mode == resolution_mode_enum.Units)
			{
				prearea.step.x = 1f;
				prearea.step.y = 1f;
				prearea.conversion_step = prearea.step;
				Vector3 size15 = preterrain1.terrain.terrainData.size;
				prearea.resolution = size15.x;
			}
			else if (prearea.resolution_mode == resolution_mode_enum.Custom)
			{
				Vector3 size16 = preterrain1.terrain.terrainData.size;
				prearea.resolution = size16.x / prearea.step.x;
				prearea.conversion_step = prearea.step;
			}
		}
	}

	public void get_terrain_parameter_settings(terrain_class preterrain1)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].settings_editor = preterrain1.settings_editor;
			terrains[i].settings_runtime = preterrain1.settings_runtime;
			if (!terrains[i].terrain || !terrains[i].terrain.terrainData)
			{
				continue;
			}
			if (terrains[i].settings_editor)
			{
				terrains[i].heightmapPixelError = terrains[i].terrain.heightmapPixelError;
				terrains[i].heightmapMaximumLOD = terrains[i].terrain.heightmapMaximumLOD;
				terrains[i].basemapDistance = terrains[i].terrain.basemapDistance;
				terrains[i].castShadows = terrains[i].terrain.castShadows;
				terrains[i].draw = terrains[i].editor_draw;
				terrains[i].treeDistance = terrains[i].terrain.treeDistance;
				terrains[i].detailObjectDistance = terrains[i].terrain.detailObjectDistance;
				terrains[i].detailObjectDensity = terrains[i].terrain.detailObjectDensity;
				terrains[i].treeBillboardDistance = terrains[i].terrain.treeBillboardDistance;
				terrains[i].treeCrossFadeLength = terrains[i].terrain.treeCrossFadeLength;
				terrains[i].treeMaximumFullLODCount = terrains[i].terrain.treeMaximumFullLODCount;
				continue;
			}
			terrains[i].script_terrainDetail = (TerrainDetail)terrains[i].terrain.gameObject.GetComponent(typeof(TerrainDetail));
			if (!terrains[i].script_terrainDetail)
			{
				terrains[i].script_terrainDetail = (TerrainDetail)terrains[i].terrain.gameObject.AddComponent(typeof(TerrainDetail));
			}
			terrains[i].heightmapPixelError = terrains[i].script_terrainDetail.heightmapPixelError;
			terrains[i].heightmapMaximumLOD = terrains[i].script_terrainDetail.heightmapMaximumLOD;
			terrains[i].basemapDistance = terrains[i].script_terrainDetail.basemapDistance;
			terrains[i].castShadows = terrains[i].script_terrainDetail.castShadows;
			terrains[i].draw = terrains[i].script_terrainDetail.draw;
			terrains[i].treeDistance = terrains[i].script_terrainDetail.treeDistance;
			terrains[i].detailObjectDistance = terrains[i].script_terrainDetail.detailObjectDistance;
			terrains[i].detailObjectDensity = terrains[i].script_terrainDetail.detailObjectDensity;
			terrains[i].treeBillboardDistance = terrains[i].script_terrainDetail.treeBillboardDistance;
			terrains[i].treeCrossFadeLength = terrains[i].script_terrainDetail.treeCrossFadeLength;
			terrains[i].treeMaximumFullLODCount = terrains[i].script_terrainDetail.treeMaximumFullLODCount;
		}
	}

	public void set_terrain_parameters(terrain_class preterrain1, terrain_class preterrain2)
	{
		preterrain1.terrain.heightmapPixelError = preterrain2.heightmapPixelError;
		preterrain1.terrain.heightmapMaximumLOD = preterrain2.heightmapMaximumLOD;
		preterrain1.terrain.basemapDistance = preterrain2.basemapDistance;
		preterrain1.terrain.castShadows = preterrain2.castShadows;
		preterrain1.terrain.treeDistance = preterrain2.treeDistance;
		preterrain1.terrain.detailObjectDistance = preterrain2.detailObjectDistance;
		preterrain1.terrain.detailObjectDensity = preterrain2.detailObjectDensity;
		preterrain1.terrain.treeBillboardDistance = preterrain2.treeBillboardDistance;
		preterrain1.terrain.treeCrossFadeLength = preterrain2.treeCrossFadeLength;
		preterrain1.terrain.treeMaximumFullLODCount = preterrain2.treeMaximumFullLODCount;
	}

	public void set_terrain_pixelerror(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.heightmapPixelError = preterrain1.heightmapPixelError;
				}
				else
				{
					preterrain1.script_terrainDetail.heightmapPixelError = preterrain1.heightmapPixelError;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].heightmapPixelError = preterrain1.heightmapPixelError;
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.heightmapPixelError = preterrain1.heightmapPixelError;
				}
				else
				{
					terrains[i].script_terrainDetail.heightmapPixelError = preterrain1.heightmapPixelError;
				}
			}
		}
	}

	public void set_terrain_heightmap_lod(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.heightmapMaximumLOD = preterrain1.heightmapMaximumLOD;
				}
				else
				{
					preterrain1.script_terrainDetail.heightmapMaximumLOD = preterrain1.heightmapMaximumLOD;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].heightmapMaximumLOD = preterrain1.heightmapMaximumLOD;
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.heightmapMaximumLOD = preterrain1.heightmapMaximumLOD;
				}
				else
				{
					terrains[i].script_terrainDetail.heightmapMaximumLOD = preterrain1.heightmapMaximumLOD;
				}
			}
		}
	}

	public void set_terrain_draw(terrain_class preterrain1, bool all_terrain, bool draw)
	{
		if (!all_terrain)
		{
			if (!preterrain1.terrain)
			{
				return;
			}
			if (draw)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.detailObjectDistance = preterrain1.detailObjectDistance;
					preterrain1.terrain.treeDistance = preterrain1.treeDistance;
					preterrain1.editor_draw = true;
				}
				else
				{
					preterrain1.script_terrainDetail.draw = true;
				}
			}
			else if (preterrain1.settings_editor)
			{
				preterrain1.terrain.detailObjectDistance = 0f;
				preterrain1.terrain.treeDistance = 0f;
				preterrain1.editor_draw = false;
			}
			else
			{
				preterrain1.script_terrainDetail.draw = false;
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if (!terrains[i].terrain)
			{
				continue;
			}
			if (draw)
			{
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.detailObjectDistance = preterrain1.detailObjectDistance;
					terrains[i].terrain.treeDistance = preterrain1.treeDistance;
					terrains[i].editor_draw = true;
				}
				else
				{
					terrains[i].script_terrainDetail.draw = true;
				}
			}
			else if (preterrain1.settings_editor)
			{
				terrains[i].terrain.detailObjectDistance = 0f;
				terrains[i].terrain.treeDistance = 0f;
				terrains[i].editor_draw = false;
			}
			else
			{
				terrains[i].script_terrainDetail.draw = false;
			}
		}
	}

	public void set_terrain_basemap_distance(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.basemapDistance = preterrain1.basemapDistance;
				}
				else
				{
					preterrain1.script_terrainDetail.basemapDistance = preterrain1.basemapDistance;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].basemapDistance = preterrain1.basemapDistance;
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.basemapDistance = preterrain1.basemapDistance;
				}
				else
				{
					terrains[i].script_terrainDetail.basemapDistance = preterrain1.basemapDistance;
				}
			}
		}
	}

	public void set_terrain_detail_distance(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.detailObjectDistance = preterrain1.detailObjectDistance;
				}
				else
				{
					preterrain1.script_terrainDetail.detailObjectDistance = preterrain1.detailObjectDistance;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].detailObjectDistance = preterrain1.detailObjectDistance;
			if ((bool)terrains[i].terrain)
			{
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.detailObjectDistance = preterrain1.detailObjectDistance;
				}
				else
				{
					terrains[i].script_terrainDetail.detailObjectDistance = preterrain1.detailObjectDistance;
				}
			}
		}
	}

	public void set_terrain_detail_density(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.detailObjectDensity = preterrain1.detailObjectDensity;
				}
				else
				{
					preterrain1.script_terrainDetail.detailObjectDensity = preterrain1.detailObjectDensity;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].detailObjectDensity = preterrain1.detailObjectDensity;
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.detailObjectDensity = preterrain1.detailObjectDensity;
				}
				else
				{
					terrains[i].script_terrainDetail.detailObjectDensity = preterrain1.detailObjectDensity;
				}
			}
		}
	}

	public void set_terrain_tree_distance(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.treeDistance = preterrain1.treeDistance;
				}
				else
				{
					preterrain1.script_terrainDetail.treeDistance = preterrain1.treeDistance;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].treeDistance = preterrain1.treeDistance;
			if ((bool)terrains[i].terrain)
			{
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.treeDistance = preterrain1.treeDistance;
				}
				else
				{
					terrains[i].script_terrainDetail.treeDistance = preterrain1.treeDistance;
				}
			}
		}
	}

	public void set_terrain_tree_billboard_distance(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.treeBillboardDistance = preterrain1.treeBillboardDistance;
				}
				else
				{
					preterrain1.script_terrainDetail.treeBillboardDistance = preterrain1.treeBillboardDistance;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].treeBillboardDistance = preterrain1.treeBillboardDistance;
			if ((bool)terrains[i].terrain)
			{
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.treeBillboardDistance = preterrain1.treeBillboardDistance;
				}
				else
				{
					terrains[i].script_terrainDetail.treeBillboardDistance = preterrain1.treeBillboardDistance;
				}
			}
		}
	}

	public void set_terrain_tree_billboard_fade_length(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.treeCrossFadeLength = preterrain1.treeCrossFadeLength;
				}
				else
				{
					preterrain1.script_terrainDetail.treeCrossFadeLength = preterrain1.treeCrossFadeLength;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].treeCrossFadeLength = preterrain1.treeCrossFadeLength;
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.treeCrossFadeLength = preterrain1.treeCrossFadeLength;
				}
				else
				{
					terrains[i].script_terrainDetail.treeCrossFadeLength = preterrain1.treeCrossFadeLength;
				}
			}
		}
	}

	public void set_terrain_tree_max_mesh(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.treeMaximumFullLODCount = preterrain1.treeMaximumFullLODCount;
				}
				else
				{
					preterrain1.script_terrainDetail.treeMaximumFullLODCount = preterrain1.treeMaximumFullLODCount;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].treeMaximumFullLODCount = preterrain1.treeMaximumFullLODCount;
			if ((bool)terrains[i].terrain)
			{
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.treeMaximumFullLODCount = preterrain1.treeMaximumFullLODCount;
				}
				else
				{
					terrains[i].script_terrainDetail.treeMaximumFullLODCount = preterrain1.treeMaximumFullLODCount;
				}
			}
		}
	}

	public void set_terrain_shadow(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				if (preterrain1.settings_editor)
				{
					preterrain1.terrain.castShadows = preterrain1.castShadows;
				}
				else
				{
					preterrain1.script_terrainDetail.castShadows = preterrain1.castShadows;
				}
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].castShadows = preterrain1.castShadows;
			if ((bool)terrains[i].terrain)
			{
				if (preterrain1.settings_editor)
				{
					terrains[i].terrain.castShadows = preterrain1.castShadows;
				}
				else
				{
					terrains[i].script_terrainDetail.castShadows = preterrain1.castShadows;
				}
			}
		}
	}

	public void set_terrain_material(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].terrain.materialTemplate = preterrain1.terrain.materialTemplate;
			}
		}
	}

	public void set_terrain_wind_speed(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				preterrain1.terrain.terrainData.wavingGrassSpeed = preterrain1.wavingGrassSpeed;
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].terrain.terrainData.wavingGrassSpeed = preterrain1.wavingGrassSpeed;
				terrains[i].wavingGrassSpeed = preterrain1.wavingGrassSpeed;
			}
		}
	}

	public void set_terrain_wind_amount(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				preterrain1.terrain.terrainData.wavingGrassAmount = preterrain1.wavingGrassAmount;
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].terrain.terrainData.wavingGrassAmount = preterrain1.wavingGrassAmount;
				terrains[i].wavingGrassAmount = preterrain1.wavingGrassAmount;
			}
		}
	}

	public void set_terrain_wind_bending(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				preterrain1.terrain.terrainData.wavingGrassStrength = preterrain1.wavingGrassStrength;
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].terrain.terrainData.wavingGrassStrength = preterrain1.wavingGrassStrength;
				terrains[i].wavingGrassStrength = preterrain1.wavingGrassStrength;
			}
		}
	}

	public void set_terrain_grass_tint(terrain_class preterrain1, bool all_terrain)
	{
		if (!all_terrain)
		{
			if ((bool)preterrain1.terrain)
			{
				preterrain1.terrain.terrainData.wavingGrassTint = preterrain1.wavingGrassTint;
			}
			return;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].terrain.terrainData.wavingGrassTint = preterrain1.wavingGrassTint;
				terrains[i].wavingGrassTint = preterrain1.wavingGrassTint;
			}
		}
	}

	public void set_terrain_settings(terrain_class preterrain1, string command)
	{
		if (!preterrain1.terrain)
		{
			return;
		}
		bool flag = false;
		bool flag2 = false;
		bool flag3 = false;
		if (command.IndexOf("(siz)") != -1)
		{
			flag = true;
		}
		if (command.IndexOf("(res)") != -1)
		{
			flag3 = true;
		}
		if (command.IndexOf("(all)") != -1)
		{
			flag2 = true;
		}
		if (flag3 || flag2)
		{
			if ((float)preterrain1.terrain.terrainData.heightmapResolution != preterrain1.heightmap_resolution)
			{
				preterrain1.terrain.terrainData.heightmapResolution = (int)preterrain1.heightmap_resolution;
				preterrain1.terrain.terrainData.size = preterrain1.size;
			}
			if ((float)preterrain1.terrain.terrainData.alphamapResolution != preterrain1.splatmap_resolution)
			{
				preterrain1.terrain.terrainData.alphamapResolution = (int)preterrain1.splatmap_resolution;
			}
			if ((float)preterrain1.terrain.terrainData.baseMapResolution != preterrain1.basemap_resolution)
			{
				preterrain1.terrain.terrainData.baseMapResolution = (int)preterrain1.basemap_resolution;
			}
			preterrain1.terrain.terrainData.SetDetailResolution((int)preterrain1.detail_resolution, (int)preterrain1.detail_resolution_per_patch);
		}
		if (flag || flag2)
		{
			Vector3 size = preterrain1.terrain.terrainData.size;
			if (preterrain1.terrain.terrainData.size != preterrain1.size)
			{
				preterrain1.terrain.terrainData.size = preterrain1.size;
			}
			Vector2 vector = default(Vector2);
			vector.x = preterrain1.size.x / size.x;
			vector.y = preterrain1.size.z / size.z;
			preterrain1.prearea.area_max.xMin = 0f;
			preterrain1.prearea.area_max.yMin = 0f;
			ref Rect area_max = ref preterrain1.prearea.area_max;
			Vector3 size2 = preterrain1.terrain.terrainData.size;
			area_max.xMax = size2.x;
			ref Rect area_max2 = ref preterrain1.prearea.area_max;
			Vector3 size3 = preterrain1.terrain.terrainData.size;
			area_max2.yMax = size3.z;
			preterrain1.prearea.area.xMin = preterrain1.prearea.area.xMin * vector.x;
			preterrain1.prearea.area.xMax = preterrain1.prearea.area.xMax * vector.x;
			preterrain1.prearea.area.yMin = preterrain1.prearea.area.yMin * vector.y;
			preterrain1.prearea.area.yMax = preterrain1.prearea.area.yMax * vector.y;
		}
		get_terrain_settings(preterrain1, "(con)" + command);
	}

	public void setTerrainAreaMax(terrain_class preterrain1)
	{
		if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData)
		{
			area_class prearea = preterrain1.prearea;
			float x = 0f;
			float y = 0f;
			Vector3 size = preterrain1.terrain.terrainData.size;
			float x2 = size.x;
			Vector3 size2 = preterrain1.terrain.terrainData.size;
			prearea.area_max = new Rect(x, y, x2, size2.z);
			preterrain1.prearea.area = preterrain1.prearea.area_max;
		}
	}

	public void set_all_terrain_area(terrain_class preterrain1)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			terrains[i].prearea.resolution_mode = preterrain1.prearea.resolution_mode;
			terrains[i].prearea.area = preterrain1.prearea.area;
			terrains[i].prearea.step = preterrain1.prearea.step;
			terrains[i].prearea.tree_resolution = preterrain1.prearea.tree_resolution;
			terrains[i].prearea.object_resolution = preterrain1.prearea.object_resolution;
			terrains[i].prearea.set_resolution_mode_text();
			terrains[i].color_terrain = new Color(0.5f, 1f, 0.5f);
		}
	}

	public void set_all_terrain_settings(terrain_class preterrain1, string command)
	{
		bool flag = false;
		bool flag2 = false;
		if (command.IndexOf("(siz)") != -1)
		{
			flag = true;
		}
		if (command.IndexOf("(res)") != -1)
		{
			flag2 = true;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			if (flag)
			{
				terrains[i].size = preterrain1.size;
			}
			if (flag2)
			{
				terrains[i].heightmap_resolution = preterrain1.heightmap_resolution;
				terrains[i].splatmap_resolution = preterrain1.splatmap_resolution;
				terrains[i].detail_resolution = preterrain1.detail_resolution;
				terrains[i].basemap_resolution = preterrain1.basemap_resolution;
				terrains[i].detail_resolution_per_patch = preterrain1.detail_resolution_per_patch;
			}
			terrains[i].color_terrain = new Color(0.5f, 1f, 0.5f);
			set_terrain_settings(terrains[i], command);
			get_terrain_settings(terrains[i], command);
		}
	}

	public void object_apply()
	{
		if (object_output && placedObjects.Count > 0)
		{
			for (int i = 0; i < placedObjects.Count; i++)
			{
				placedObjects[i].SetActive(value: true);
			}
			placedObjects.Clear();
		}
	}

	public void terrain_apply(terrain_class preterrain1)
	{
		if ((runtime || settings.direct_colormap) && color_output)
		{
			preterrain1.ColorGlobal.Apply();
		}
		if (splat_output || (color_output && !button_export && !settings.direct_colormap))
		{
			for (int i = 0; i < preterrain1.splat_alpha.Length; i++)
			{
				preterrain1.splat_alpha[i].Apply();
			}
			preterrain1.terrain.terrainData.SetAlphamaps(0, 0, preterrain1.terrain.terrainData.GetAlphamaps(0, 0, 1, 1));
		}
		if (grass_output)
		{
			for (int j = default(int); j < preterrain1.grass.Length; j++)
			{
				preterrain1.terrain.terrainData.SetDetailLayer(0, 0, j, grass_detail[j].detail);
				for (int k = 0; (float)k < preterrain1.detail_resolution; k++)
				{
					for (int l = 0; (float)l < preterrain1.detail_resolution; l++)
					{
						grass_detail[j].detail[l, k] = 0;
					}
				}
			}
		}
		if (heightmap_output)
		{
			preterrain1.terrain.terrainData.SetHeights(0, 0, heights);
			if (smooth_command)
			{
				smooth_terrain(preterrain1, smooth_tool_layer_strength);
			}
		}
		if (tree_output)
		{
			preterrain1.terrain.terrainData.treeInstances = new TreeInstance[tree_instances.Count];
			preterrain1.terrain.terrainData.treeInstances = tree_instances.ToArray();
		}
		preterrain1.terrain.Flush();
	}

	public void FlushTerrains()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			if (terrains[i].terrain != null && terrains[i].active)
			{
				terrains[i].terrain.Flush();
			}
		}
	}

	public float get_terrain_alpha(terrain_class preterrain1, int local_x, int local_y, int alpha_index)
	{
		int num = alpha_index / 4;
		return preterrain1.splat_alpha[num].GetPixel(local_x, local_y)[alpha_index - num * 4];
	}

	public void set_all_tree_filters(tree_output_class tree_output, int tree_number, bool all)
	{
		for (int i = 0; i < tree_output.tree.Count; i++)
		{
			if (tree_output.tree_value.active[i] || all)
			{
				if (i != tree_number)
				{
					erase_filters(tree_output.tree[i].prefilter);
					tree_output.tree[i].prefilter = copy_prefilter(tree_output.tree[tree_number].prefilter);
				}
				if (!(tree_output.tree[i].color_tree[0] >= 1.5f))
				{
					tree_output.tree[i].color_tree = tree_output.tree[i].color_tree + new Color(0.5f, 0.5f, 0.5f, 0.5f);
				}
			}
		}
	}

	public void set_all_tree_precolor_range(tree_output_class tree_output, int tree_number, bool all)
	{
		for (int i = 0; i < tree_output.tree.Count; i++)
		{
			if (tree_output.tree_value.active[i] || all)
			{
				if (i != tree_number)
				{
					tree_output.tree[i].precolor_range = copy_precolor_range(tree_output.tree[tree_number].precolor_range);
				}
				if (!(tree_output.tree[i].color_tree[0] >= 1.5f))
				{
					tree_output.tree[i].color_tree = tree_output.tree[i].color_tree + new Color(0.5f, 0.5f, 0.5f, 0.5f);
				}
			}
		}
	}

	public bool set_auto_object(object_output_class object_output)
	{
		int result;
		if (!object_output.search_object)
		{
			result = 0;
		}
		else
		{
			Transform[] componentsInChildren = object_output.search_object.GetComponentsInChildren<Transform>();
			string text = null;
			add_object(object_output, object_output.@object.Count);
			object_output.@object[object_output.@object.Count - 1].object1 = componentsInChildren[1].gameObject;
			text = componentsInChildren[1].name;
			for (int i = 2; i < componentsInChildren.Length; i++)
			{
				if (componentsInChildren[i].name != text)
				{
					add_object(object_output, object_output.@object.Count);
					object_output.@object[object_output.@object.Count - 1].object1 = componentsInChildren[i].gameObject;
					text = componentsInChildren[i].name;
				}
				else if (object_output.search_erase_doubles)
				{
					UnityEngine.Object.DestroyImmediate(componentsInChildren[i].gameObject);
				}
			}
			result = 1;
		}
		return (byte)result != 0;
	}

	public void create_terrain(terrain_class preterrain, Vector2 tiles)
	{
		TerrainData terrainData = null;
		GameObject gameObject = null;
		Terrain terrain = null;
		TerrainCollider terrainCollider = null;
		string text = null;
		string text2 = null;
		int num = default(int);
		DeleteTerrain(terrains[0]);
		clear_terrain_list(deleteTerrainHierarchy: true);
		if (terrains[0].size.x == 0f)
		{
			terrains[0].size.x = 1000f;
		}
		if (terrains[0].size.y == 0f)
		{
			terrains[0].size.y = 500f;
		}
		if (terrains[0].size.z == 0f)
		{
			terrains[0].size.z = 1000f;
		}
		for (int i = 0; (float)i < tiles.y; i++)
		{
			for (int j = 0; (float)j < tiles.x; j++)
			{
				if (j != 0 || i != 0)
				{
					terrains.Add(new terrain_class());
				}
				num = terrains.Count - 1;
				if (j != 0 || i != 0)
				{
					terrains[num] = copy_terrain(terrains[0]);
				}
				terrains[num].tile_x = j;
				terrains[num].tile_z = i;
				terrains[num].tiles = tiles;
				terrains[num].index = num;
				gameObject = new GameObject();
				if ((bool)terrain_parent)
				{
					gameObject.transform.parent = terrain_parent;
				}
				terrain = (Terrain)gameObject.AddComponent(typeof(Terrain));
				terrainCollider = (TerrainCollider)gameObject.AddComponent(typeof(TerrainCollider));
				text = "_x" + j.ToString() + "_y" + i.ToString();
				terrain.name = terrain_scene_name + text;
				terrainData = new TerrainData();
				terrainData.size = terrains[0].size;
				terrain.terrainData = terrainData;
				terrainCollider.terrainData = terrainData;
				terrains[num].terrain = terrain;
				set_terrain_splat_textures(terrains[num], terrains[num]);
				set_terrain_trees(terrains[num]);
				set_terrain_details(terrains[num]);
				set_terrain_settings(terrains[num], "(all)");
				if (settings.copy_terrain_material)
				{
					terrain.materialTemplate = terrains[0].terrain.materialTemplate;
				}
				set_terrain_parameters(terrains[num], terrains[0]);
				get_terrain_parameter_settings(terrains[num]);
				terrains[num].foldout = false;
				if ((bool)terrains[0].rtp_script)
				{
					assign_rtp_single(terrains[num]);
				}
			}
		}
		FitTerrainTiles(preterrain, refit: true);
	}

	public void create_terrain2(terrain_class preterrain1, int length, int name_number)
	{
		for (int i = 0; i < length; i++)
		{
			TerrainData terrainData = new TerrainData();
			terrainData.heightmapResolution = (int)preterrain1.heightmap_resolution;
			terrainData.baseMapResolution = (int)preterrain1.basemap_resolution;
			terrainData.alphamapResolution = (int)preterrain1.splatmap_resolution;
			terrainData.SetDetailResolution((int)preterrain1.detail_resolution, (int)preterrain1.detail_resolution_per_patch);
			if (preterrain1.size.x == 0f)
			{
				preterrain1.size.x = 1000f;
			}
			if (preterrain1.size.y == 0f)
			{
				preterrain1.size.y = 500f;
			}
			if (preterrain1.size.z == 0f)
			{
				preterrain1.size.z = 1000f;
			}
			terrainData.size = preterrain1.size;
			GameObject gameObject = Terrain.CreateTerrainGameObject(terrainData);
			if ((bool)preterrain1.parent)
			{
				gameObject.transform.parent = preterrain1.parent;
			}
			Terrain terrain = (Terrain)gameObject.GetComponent(typeof(Terrain));
			terrain.name = terrain_scene_name + (i + name_number);
			if (terrains.Count < i + name_number)
			{
				set_terrain_length(terrains.Count + 1);
			}
			terrains[i + name_number - 1].terrain = terrain;
			if (i != 0)
			{
				set_terrain_parameters(terrains[i + name_number - 1], terrains[name_number - 1]);
			}
			else
			{
				set_terrain_parameters(terrains[i + name_number - 1], terrains[i + name_number - 1]);
			}
			get_terrain_settings(terrains[i + name_number - 1], "(res)(con)(fir)");
			terrains[i + name_number - 1].tile_x = 0f;
			terrains[i + name_number - 1].tile_z = 0f;
			terrains[i + name_number - 1].tiles = new Vector2(1f, 1f);
			terrains[i + name_number - 1].terrain.transform.position = new Vector3((0f - preterrain1.size.x) / 2f, 0f, (0f - preterrain1.size.z) / 2f);
			terrains[i + name_number - 1].prearea.max();
		}
		set_all_terrain_area(preterrain1);
		set_all_terrain_splat_textures(preterrain1, copy: true, flash: true);
		assign_all_terrain_splat_alpha();
		set_all_terrain_trees(preterrain1);
		set_all_terrain_details(preterrain1);
	}

	public void assign_all_terrain_splat_alpha()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			assign_terrain_splat_alpha(terrains[i]);
		}
	}

	public void assign_terrain_splat_alpha(terrain_class preterrain1)
	{
		if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData && preterrain1.terrain.terrainData.splatPrototypes.Length >= 1)
		{
			Type type = preterrain1.terrain.terrainData.GetType();
			PropertyInfo property = type.GetProperty("alphamapTextures", BindingFlags.Instance | BindingFlags.NonPublic);
			if (RuntimeServices.EqualityOperator(property, null))
			{
				property = type.GetProperty("alphamapTextures", BindingFlags.Instance | BindingFlags.Public);
			}
			if (!RuntimeServices.EqualityOperator(property, null))
			{
				preterrain1.splat_alpha = (property.GetValue(preterrain1.terrain.terrainData, null) as Texture2D[]);
			}
			else
			{
				UnityEngine.Debug.LogError("Can't access alphamapTexture directly...");
			}
		}
	}

	public void randomize_layer_offset(layer_output_enum layer_output, Vector2 offset, int seed)
	{
		UnityEngine.Random.seed = seed;
		for (int i = 0; i < prelayers[0].layer.Count; i++)
		{
			if (prelayers[0].layer[i].output == layer_output)
			{
				prelayers[0].layer[i].offset = new Vector2(UnityEngine.Random.Range(offset.x, offset.y), UnityEngine.Random.Range(offset.x, offset.y));
				prelayers[0].layer[i].offset_middle = prelayers[0].layer[i].offset;
			}
		}
	}

	public void set_auto_terrain()
	{
		Terrain[] array = (Terrain[])UnityEngine.Object.FindObjectsOfType(typeof(Terrain));
		if (array.Length > 0)
		{
			terrains.Clear();
			int num = default(int);
			for (num = 0; num < array.Length; num++)
			{
				string name = array[num].name;
				string s = Regex.Replace(name, "[^0-9]", string.Empty);
				float result = 0f;
				if (float.TryParse(s, out result))
				{
					terrains.Add(new terrain_class());
					terrains[terrains.Count - 1].terrain = array[num];
					terrains[terrains.Count - 1].name = terrains[terrains.Count - 1].terrain.name;
					terrains[terrains.Count - 1].index = terrains.Count - 1;
					get_terrain_settings(terrains[terrains.Count - 1], "(all)(fir)(spl)(tre)");
				}
			}
		}
		set_smooth_tool_terrain_popup();
		set_terrain_text();
	}

	public void AutoSearchTerrains()
	{
		Terrain[] array = null;
		Terrain terrain = null;
		Rect rect = default(Rect);
		Vector2 tile = default(Vector2);
		Vector2 zero = Vector2.zero;
		List<TempTerrain_Class> list = new List<TempTerrain_Class>();
		array = ((!(terrainSearchParent != null)) ? ((Terrain[])UnityEngine.Object.FindObjectsOfType(typeof(Terrain))) : terrainSearchParent.GetComponentsInChildren<Terrain>());
		if (array.Length == 0)
		{
			return;
		}
		terrains.Clear();
		rect = GetTerrainsArea(array);
		float width = rect.width;
		Vector3 size = array[0].terrainData.size;
		zero.x = Mathf.Round(width / size.x);
		float num = rect.height;
		Vector3 size2 = array[0].terrainData.size;
		zero.y = Mathf.Round(num / size2.z);
		foreach (Terrain terrain_1 in array)
		{
			Vector3 vector = terrain_1.transform.position;
			float num2 = vector.x - rect.xMin;
			Vector3 size3 = terrain_1.terrainData.size;
			tile.x = Mathf.Round(num2 / size3.x);
			Vector3 vector2 = terrain_1.transform.position;
			float num3 = vector2.z - rect.yMin;
			Vector3 size4 = terrain_1.terrainData.size;
			tile.y = Mathf.Round(num3 / size4.z);
			list.Add(new TempTerrain_Class(terrain_1, tile));
		}
		for (int j = 0; (float)j < zero.y; j++)
		{
			for (int k = 0; (float)k < zero.x; k++)
			{
				for (int i = 0; i < list.Count; i++)
				{
					if ((float)k == list[i].tile.x && (float)j == list[i].tile.y)
					{
						terrains.Add(new terrain_class());
						terrains[terrains.Count - 1].terrain = list[i].terrain;
						terrains[terrains.Count - 1].tile_x = list[i].tile.x;
						terrains[terrains.Count - 1].tile_z = list[i].tile.y;
						terrains[terrains.Count - 1].tiles = zero;
						get_terrain_settings(terrains[terrains.Count - 1], "(all)(fir)(spl)(tre)");
						break;
					}
				}
			}
		}
	}

	public void AutoSearchTiles()
	{
		terrain_class terrain_class = null;
		Rect rect = default(Rect);
		Vector2 vector = default(Vector2);
		Vector2 zero = Vector2.zero;
		List<terrain_class> list = new List<terrain_class>();
		int num = -1;
		rect = GetTerrainsArea();
		for (int i = 0; i < terrains.Count; i++)
		{
			if (terrains[i].terrain != null && terrains[i].terrain.terrainData != null)
			{
				num = i;
				break;
			}
		}
		if (num == -1)
		{
			return;
		}
		float width = rect.width;
		Vector3 size = terrains[num].terrain.terrainData.size;
		zero.x = Mathf.Round(width / size.x);
		float num2 = rect.height;
		Vector3 size2 = terrains[num].terrain.terrainData.size;
		zero.y = Mathf.Round(num2 / size2.z);
		for (int i = 0; i < terrains.Count; i++)
		{
			terrain_class = terrains[i];
			terrain_class.tiles = zero;
			list.Add(terrains[i]);
			if (!(terrain_class.terrain == null) && !(terrain_class.terrain.terrainData == null))
			{
				terrain_class terrain_class2 = terrain_class;
				Vector3 vector2 = terrain_class.terrain.transform.position;
				float num3 = vector2.x - rect.xMin;
				Vector3 size3 = terrain_class.terrain.terrainData.size;
				terrain_class2.tile_x = Mathf.Round(num3 / size3.x);
				terrain_class terrain_class3 = terrain_class;
				Vector3 vector3 = terrain_class.terrain.transform.position;
				float num4 = vector3.z - rect.yMin;
				Vector3 size4 = terrain_class.terrain.terrainData.size;
				terrain_class3.tile_z = Mathf.Round(num4 / size4.z);
			}
		}
		terrains.Clear();
		for (int j = 0; (float)j < zero.y; j++)
		{
			for (int k = 0; (float)k < zero.x; k++)
			{
				for (int i = 0; i < list.Count; i++)
				{
					if ((float)k == list[i].tile_x && (float)j == list[i].tile_z)
					{
						terrains.Add(list[i]);
						break;
					}
				}
			}
		}
	}

	public Rect GetTerrainsArea(Terrain[] terrainObjects)
	{
		float num = 1E+11f;
		float num2 = -1E+11f;
		float num3 = 1E+11f;
		float num4 = -1E+11f;
		Vector3 vector = default(Vector3);
		for (int i = 0; i < terrainObjects.Length; i++)
		{
			if (!(terrainObjects[i].terrainData == null))
			{
				vector = terrainObjects[i].terrainData.size;
				Vector3 vector2 = terrainObjects[i].transform.position;
				if (!(vector2.x > num))
				{
					Vector3 vector3 = terrainObjects[i].transform.position;
					num = vector3.x;
				}
				Vector3 vector4 = terrainObjects[i].transform.position;
				if (!(vector4.z > num3))
				{
					Vector3 vector5 = terrainObjects[i].transform.position;
					num3 = vector5.z;
				}
				Vector3 vector6 = terrainObjects[i].transform.position;
				if (!(vector6.x + vector.x < num2))
				{
					Vector3 vector7 = terrainObjects[i].transform.position;
					num2 = vector7.x + vector.x;
				}
				Vector3 vector8 = terrainObjects[i].transform.position;
				if (!(vector8.z + vector.z < num4))
				{
					Vector3 vector9 = terrainObjects[i].transform.position;
					num4 = vector9.z + vector.z;
				}
			}
		}
		return new Rect(num, num3, num2 - num, num4 - num3);
	}

	public Rect GetTerrainsArea()
	{
		float num = 1E+11f;
		float num2 = -1E+11f;
		float num3 = 1E+11f;
		float num4 = -1E+11f;
		Vector3 vector = default(Vector3);
		for (int i = 0; i < terrains.Count; i++)
		{
			if (!(terrains[i].terrain == null) && !(terrains[i].terrain.terrainData == null))
			{
				vector = terrains[i].terrain.terrainData.size;
				Vector3 vector2 = terrains[i].terrain.transform.position;
				if (!(vector2.x > num))
				{
					Vector3 vector3 = terrains[i].terrain.transform.position;
					num = vector3.x;
				}
				Vector3 vector4 = terrains[i].terrain.transform.position;
				if (!(vector4.z > num3))
				{
					Vector3 vector5 = terrains[i].terrain.transform.position;
					num3 = vector5.z;
				}
				Vector3 vector6 = terrains[i].terrain.transform.position;
				if (!(vector6.x + vector.x < num2))
				{
					Vector3 vector7 = terrains[i].terrain.transform.position;
					num2 = vector7.x + vector.x;
				}
				Vector3 vector8 = terrains[i].terrain.transform.position;
				if (!(vector8.z + vector.z < num4))
				{
					Vector3 vector9 = terrains[i].terrain.transform.position;
					num4 = vector9.z + vector.z;
				}
			}
		}
		return new Rect(num, num3, num2 - num, num4 - num3);
	}

	public void set_auto_mesh()
	{
		MeshFilter[] array = null;
		array = ((!(object_search == null)) ? object_search.GetComponentsInChildren<MeshFilter>() : ((MeshFilter[])UnityEngine.Object.FindObjectsOfType(typeof(MeshFilter))));
		if (RuntimeServices.EqualityOperator(array, null) || array.Length <= 0)
		{
			return;
		}
		meshes.Clear();
		for (int i = 0; i < array.Length; i++)
		{
			if ((array[i].gameObject.layer & meshes_layer) == meshes_layer)
			{
				meshes.Add(new mesh_class());
				meshes[meshes.Count - 1].gameObject = array[i].gameObject;
				meshes[meshes.Count - 1].transform = array[i].transform;
				meshes[meshes.Count - 1].collider = (MeshCollider)array[i].GetComponent(typeof(MeshCollider));
				meshes[meshes.Count - 1].meshFilter = (MeshFilter)array[i].GetComponent(typeof(MeshFilter));
				meshes[meshes.Count - 1].mesh = meshes[meshes.Count - 1].meshFilter.sharedMesh;
			}
		}
	}

	public int get_rank_in_list(List<int> list, int number)
	{
		int num = 0;
		for (int i = 0; i < list.Count; i++)
		{
			if (list[number] > list[i])
			{
				num++;
			}
		}
		return num;
	}

	public bool check_terrains_assigned()
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < terrains.Count)
			{
				if (!terrains[num].terrain)
				{
					result = 0;
					break;
				}
				if (!terrains[num].terrain.terrainData)
				{
					result = 0;
					break;
				}
				num++;
				continue;
			}
			result = 1;
			break;
		}
		return (byte)result != 0;
	}

	public bool find_mesh()
	{
		return (prelayer.count_terrain < meshes.Count) ? true : false;
	}

	public bool find_terrain(bool first)
	{
		ulong num = default(ulong);
		int num2 = prelayer.count_terrain;
		int result;
		while (true)
		{
			if (num2 < terrains.Count)
			{
				if (terrains[num2].active)
				{
					tree_instances.Clear();
					for (int i = 0; i < settings.treemap.Count; i++)
					{
						if (tree_output && settings.treemap[i].load && (bool)settings.treemap[i].map)
						{
							load_tree(i, num2);
						}
					}
					if ((runtime || settings.direct_colormap) && color_output && (bool)terrains[num2].rtp_script)
					{
						Type type = terrains[num2].rtp_script.GetType();
						FieldInfo field = type.GetField("ColorGlobal");
						terrains[num2].ColorGlobal = (field.GetValue(terrains[num2].rtp_script) as Texture2D);
					}
					if (object_output && settings.parentObjectsTerrain)
					{
						terrains[num2].objectParent = new GameObject();
						terrains[num2].objectParent.transform.parent = terrains[num2].terrain.transform;
						terrains[num2].objectParent.name = "Objects";
					}
					if (!first)
					{
						if (heightmap_output)
						{
							num = (ulong)(terrains[num2].heightmap_resolution * terrains[num2].heightmap_resolution);
							if (num != (ulong)heights.Length)
							{
								heights = (float[,])System.Array.CreateInstance(typeof(float), new int[2]
								{
									(int)terrains[num2].heightmap_resolution,
									(int)terrains[num2].heightmap_resolution
								});
							}
						}
						if (grass_output)
						{
							if (terrains[num2].terrain.terrainData.detailPrototypes.Length > grass_detail.Length)
							{
								grass_detail = new detail_class[terrains[num2].terrain.terrainData.detailPrototypes.Length];
							}
							for (int j = 0; j < grass_detail.Length; j++)
							{
								if (grass_detail[j] == null)
								{
									grass_detail[j] = new detail_class();
								}
								if (grass_detail[j].detail != null)
								{
									if (terrains[num2].detail_resolution * terrains[num2].detail_resolution != (float)grass_detail[j].detail.Length)
									{
										grass_detail[j].detail = (int[,])System.Array.CreateInstance(typeof(int), new int[2]
										{
											(int)terrains[num2].detail_resolution,
											(int)terrains[num2].detail_resolution
										});
									}
								}
								else
								{
									grass_detail[j].detail = (int[,])System.Array.CreateInstance(typeof(int), new int[2]
									{
										(int)terrains[num2].detail_resolution,
										(int)terrains[num2].detail_resolution
									});
								}
							}
						}
					}
					for (int k = 0; k < settings.grassmap.Count; k++)
					{
						if (grass_output && settings.grassmap[k].load && (bool)settings.grassmap[k].map)
						{
							load_grass(k, num2);
						}
					}
					if (prelayer.count_terrain > 0)
					{
						set_image_terrain_mode(num2);
					}
					result = 1;
					break;
				}
				prelayer.count_terrain++;
				num2++;
				continue;
			}
			result = 0;
			break;
		}
		return (byte)result != 0;
	}

	public void load_tree(int treemap_index, int terrain_index)
	{
		tree_script = (settings.treemap[treemap_index].map.GetComponent("save_trees") as save_trees);
		if (tree_script.tree_save.Count - 1 < terrain_index)
		{
			return;
		}
		int count = tree_script.tree_save[terrain_index].treeInstances.Count;
		TreeInstance item = default(TreeInstance);
		int num = default(int);
		Vector3 size = terrains[terrain_index].terrain.terrainData.size;
		for (int i = 0; i < count; i++)
		{
			num = tree_script.tree_save[terrain_index].treeInstances[i].prototypeIndex;
			if (UnityEngine.Random.Range(0f, 1f) <= settings.treemap[treemap_index].tree_param[num].density)
			{
				item.position = tree_script.tree_save[terrain_index].treeInstances[i].position;
				item.position.y = terrains[terrain_index].terrain.terrainData.GetInterpolatedHeight(item.position.x, item.position.z) / size.y;
				item.widthScale = tree_script.tree_save[terrain_index].treeInstances[i].widthScale * settings.treemap[treemap_index].tree_param[num].scale;
				item.heightScale = tree_script.tree_save[terrain_index].treeInstances[i].heightScale * settings.treemap[treemap_index].tree_param[num].scale;
				item.color = tree_script.tree_save[terrain_index].treeInstances[i].color;
				item.lightmapColor = tree_script.tree_save[terrain_index].treeInstances[i].lightmapColor;
				item.prototypeIndex = settings.treemap[treemap_index].tree_param[num].prototype;
				tree_instances.Add(item);
			}
		}
	}

	public void load_grass(int grassmap_index, int terrain_index)
	{
		grass_script = (settings.grassmap[grassmap_index].map.GetComponent("save_grass") as save_grass);
		if (grass_script.grass_save.Count - 1 < terrain_index)
		{
			return;
		}
		int num = grass_script.grass_save[terrain_index].resolution;
		int num2 = default(int);
		int count = grass_script.grass_save[terrain_index].details.Count;
		float num3 = (float)num / terrains[terrain_index].detail_resolution * ((float)num / terrains[terrain_index].detail_resolution);
		int num4 = default(int);
		for (int i = 0; i < count && i <= terrains[terrain_index].terrain.terrainData.detailPrototypes.Length - 1; i++)
		{
			num4 = grass_detail[settings.grassmap[grassmap_index].grass_param[i].prototype].detail.Length;
			num2 = (int)terrains[terrain_index].detail_resolution;
			for (int j = 0; j < num4; j++)
			{
				grass_detail[settings.grassmap[grassmap_index].grass_param[i].prototype].detail[j - j / num2 * num2, j / num2] = (int)((float)grass_detail[settings.grassmap[grassmap_index].grass_param[i].prototype].detail[j - j / num2 * num2, j / num2] + (float)grass_script.grass_save[terrain_index].details[i].detail[(int)((float)j * num3)] * settings.grassmap[grassmap_index].grass_param[i].density);
			}
		}
	}

	public void assign_rtp(bool active, bool open_link)
	{
		Type type = null;
		FieldInfo fieldInfo = null;
		Type type2 = null;
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				if (active)
				{
					assign_rtp_single(terrains[i]);
				}
				else
				{
					terrains[i].rtp_script = null;
				}
			}
		}
	}

	public void assign_rtp_single(terrain_class terrain1)
	{
	}

	public void center_terrain_position(terrain_class preterrain1)
	{
		if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData)
		{
			Transform transform = preterrain1.terrain.transform;
			Vector3 size = preterrain1.terrain.terrainData.size;
			float x = (0f - size.x) / 2f;
			float y = 0f;
			Vector3 size2 = preterrain1.terrain.terrainData.size;
			transform.position = new Vector3(x, y, (0f - size2.z) / 2f);
		}
	}

	public bool check_terrains_square()
	{
		float f = terrains.Count;
		float num = Mathf.Round(Mathf.Sqrt(f));
		return (num == Mathf.Sqrt(f)) ? true : false;
	}

	public int FitTerrainTiles(terrain_class preterrain1, bool refit)
	{
		Vector3 size = preterrain1.size;
		Vector2 tiles = preterrain1.tiles;
		Vector3 vector = new Vector3(0f - size.x * tiles.x / 2f, 0f, 0f - size.z * tiles.y / 2f);
		Vector3 vector2 = default(Vector3);
		set_all_terrain_settings(preterrain1, "(siz)");
		if (refit)
		{
			for (int i = 0; i < terrains.Count; i++)
			{
				vector2 = vector + new Vector3(terrains[i].tile_x * size.x, 0f, terrains[i].tile_z * size.z);
				terrains[i].color_terrain = new Color(0.5f, 1f, 0.5f);
				if (terrains[i].terrain != null)
				{
					terrains[i].terrain.transform.position = vector2;
				}
			}
		}
		tile_resolution = (int)(tiles.x * size.x);
		terrains[0].SetAllNeighbors(terrains);
		set_neighbor2(1);
		return 1;
	}

	public int fit_terrain_tiles(terrain_class preterrain1, bool refit)
	{
		int result;
		if (terrains.Count < 2)
		{
			center_terrain_position(terrains[0]);
			result = 1;
		}
		else if (!check_terrains_assigned())
		{
			result = -2;
		}
		else
		{
			Vector3 size = preterrain1.size;
			float f = terrains.Count;
			float num = Mathf.Round(Mathf.Sqrt(f));
			if (num != Mathf.Sqrt(f))
			{
				reset_terrains_tiles(this);
				result = -3;
			}
			else
			{
				set_all_terrain_settings(preterrain1, "(siz)");
				for (float num2 = 0f; num2 < num; num2 += 1f)
				{
					for (float num3 = 0f; num3 < num; num3 += 1f)
					{
						float num4 = num2 * num + num3;
						if (!(num4 >= (float)terrains.Count))
						{
							Vector3 vector = default(Vector3);
							Vector3 vector2 = default(Vector3);
							if (num == 2f)
							{
								vector2.z = num - num3 - 2f;
								vector.z = vector2.z * size.z;
								vector2.x = 0f - num + num2 + 1f;
								vector.x = vector2.x * size.x;
								vector.y = 0f;
							}
							else
							{
								vector2.z = (num - num3 * 2f - 2f) / 2f;
								vector.z = vector2.z * size.z;
								vector2.x = (0f - num + num2 * 2f) / 2f;
								vector.x = vector2.x * size.x;
								vector.y = 0f;
							}
							if (refit)
							{
								terrains[(int)num4].terrain.transform.position = vector;
							}
							terrains[(int)num4].tile_x = num2;
							terrains[(int)num4].tile_z = num - num3 - 1f;
							terrains[(int)num4].tiles.x = num;
							terrains[(int)num4].tiles.y = num;
							terrains[(int)num4].color_terrain = new Color(0.5f, 1f, 0.5f);
						}
					}
				}
				tile_resolution = (int)(num * size.x);
				terrains[0].SetAllNeighbors(terrains);
				set_neighbor2(1);
				result = 1;
			}
		}
		return result;
	}

	public void set_neighbor2(int mode)
	{
		TerrainNeighbors terrainNeighbors = null;
		int num = default(int);
		for (int i = 0; i < terrains.Count; i++)
		{
			if (!terrains[i].terrain)
			{
				continue;
			}
			terrainNeighbors = (TerrainNeighbors)terrains[i].terrain.GetComponent(typeof(TerrainNeighbors));
			if (mode == 1)
			{
				if (!terrainNeighbors)
				{
					terrainNeighbors = (TerrainNeighbors)terrains[i].terrain.gameObject.AddComponent(typeof(TerrainNeighbors));
				}
				terrainNeighbors.left = null;
				terrainNeighbors.top = null;
				terrainNeighbors.right = null;
				terrainNeighbors.bottom = null;
				num = search_tile((int)(terrains[i].tile_x - 1f), (int)terrains[i].tile_z);
				if (num != -1)
				{
					terrainNeighbors.left = terrains[num].terrain;
				}
				num = search_tile((int)terrains[i].tile_x, (int)(terrains[i].tile_z + 1f));
				if (num != -1)
				{
					terrainNeighbors.top = terrains[num].terrain;
				}
				num = search_tile((int)(terrains[i].tile_x + 1f), (int)terrains[i].tile_z);
				if (num != -1)
				{
					terrainNeighbors.right = terrains[num].terrain;
				}
				num = search_tile((int)terrains[i].tile_x, (int)(terrains[i].tile_z - 1f));
				if (num != -1)
				{
					terrainNeighbors.bottom = terrains[num].terrain;
				}
			}
			if (mode == -1 && (bool)terrainNeighbors)
			{
				UnityEngine.Object.DestroyImmediate(terrainNeighbors);
			}
		}
	}

	public void set_detail_script(int mode)
	{
		TerrainDetail terrainDetail = null;
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrainDetail = (TerrainDetail)terrains[i].terrain.GetComponent(typeof(TerrainDetail));
				if (mode == 1 && !terrainDetail)
				{
					terrainDetail = (TerrainDetail)terrains[i].terrain.gameObject.AddComponent(typeof(TerrainDetail));
				}
				if (mode == -1 && (bool)terrainDetail)
				{
					UnityEngine.Object.DestroyImmediate(terrainDetail);
				}
			}
		}
	}

	public int search_tile(int tile_x, int tile_z)
	{
		int result;
		if ((float)tile_x > terrains[0].tiles.x - 1f || tile_x < 0)
		{
			result = -1;
		}
		else if ((float)tile_z > terrains[0].tiles.y - 1f || tile_z < 0)
		{
			result = -1;
		}
		else
		{
			int num = 0;
			while (true)
			{
				if (num < terrains.Count)
				{
					if (terrains[num].tile_x == (float)tile_x && terrains[num].tile_z == (float)tile_z)
					{
						result = num;
						break;
					}
					num++;
					continue;
				}
				result = -1;
				break;
			}
		}
		return result;
	}

	public void set_all_trees_settings_terrain(terrain_class preterrain1, int tree_number)
	{
		for (int i = 0; i < preterrain1.treePrototypes.Count; i++)
		{
			preterrain1.treePrototypes[i].bendFactor = preterrain1.treePrototypes[tree_number].bendFactor;
		}
		if (!(preterrain1.color_terrain[0] >= 1.5f))
		{
			preterrain1.color_terrain += new Color(0.5f, 1f, 0.5f, 0.5f);
		}
	}

	public void set_all_trees_settings_terrains(terrain_class preterrain1, int tree_number)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			for (int j = 0; j < preterrain1.treePrototypes.Count; j++)
			{
				if (terrains[i].treePrototypes.Count - 1 >= j)
				{
					terrains[i].treePrototypes[j].bendFactor = preterrain1.treePrototypes[tree_number].bendFactor;
				}
			}
			check_synchronous_terrain_trees(terrains[i]);
			if (!(terrains[i].color_terrain[0] >= 1.5f))
			{
				terrains[i].color_terrain = terrains[i].color_terrain + new Color(0.5f, 1f, 0.5f, 0.5f);
			}
		}
	}

	public void set_all_terrain_splat_textures(terrain_class preterrain1, bool copy, bool flash)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				if (copy)
				{
					set_terrain_splat_textures(preterrain1, terrains[i]);
				}
				else
				{
					set_terrain_splat_textures(terrains[i], terrains[i]);
				}
				get_terrain_splat_textures(terrains[i]);
				if (flash && !(terrains[i].color_terrain[0] >= 1.5f))
				{
					terrains[i].color_terrain = new Color(0.5f, 1f, 0.5f);
				}
			}
		}
	}

	public void set_all_terrain_color_textures(bool flash)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			set_terrain_color_textures(terrains[i]);
			if (flash && !(terrains[i].color_terrain[0] >= 1.5f))
			{
				terrains[i].color_terrain = new Color(0.5f, 1f, 0.5f);
			}
		}
	}

	public void set_terrain_color_textures(terrain_class preterrain1)
	{
		if (!preterrain1.terrain)
		{
			return;
		}
		object value = default(object);
		FieldInfo field2 = default(FieldInfo);
		FieldInfo field3 = default(FieldInfo);
		FieldInfo field4 = default(FieldInfo);
		Texture2D[] array = default(Texture2D[]);
		Texture2D[] array2 = default(Texture2D[]);
		Texture2D[] array3 = default(Texture2D[]);
		if ((bool)preterrain1.rtp_script)
		{
			Type type = preterrain1.rtp_script.GetType();
			FieldInfo field = type.GetField("globalSettingsHolder");
			value = field.GetValue(preterrain1.rtp_script);
			Type type2 = value.GetType();
			field2 = type2.GetField("splats");
			field3 = type2.GetField("Bumps");
			field4 = type2.GetField("Heights");
			array = new Texture2D[preterrain1.splatPrototypes.Count];
			array2 = new Texture2D[preterrain1.splatPrototypes.Count];
			array3 = new Texture2D[preterrain1.splatPrototypes.Count];
		}
		List<SplatPrototype> list = new List<SplatPrototype>();
		for (int i = 0; i < settings.color_splatPrototypes.Length; i++)
		{
			list.Add(new SplatPrototype());
			if ((bool)preterrain1.rtp_script && (bool)settings.color_splatPrototypes[i].texture)
			{
				array[i] = settings.color_splatPrototypes[i].texture;
				array2[i] = null;
				array3[i] = null;
			}
			if ((bool)settings.color_splatPrototypes[i].texture)
			{
				list[i].texture = settings.color_splatPrototypes[i].texture;
				list[i].tileSize = settings.color_splatPrototypes[i].tileSize;
				list[i].tileOffset = settings.color_splatPrototypes[i].tileOffset;
			}
		}
		preterrain1.terrain.terrainData.splatPrototypes = list.ToArray();
		if ((bool)preterrain1.rtp_script)
		{
			field2.SetValue(value, array);
			field3.SetValue(value, array2);
			field4.SetValue(value, array3);
		}
	}

	public void set_terrain_splat_textures(terrain_class preterrain1, terrain_class preterrain2)
	{
		if (!preterrain1.terrain)
		{
			return;
		}
		object value = default(object);
		FieldInfo field2 = default(FieldInfo);
		FieldInfo field3 = default(FieldInfo);
		FieldInfo field4 = default(FieldInfo);
		Texture2D[] array = default(Texture2D[]);
		Texture2D[] array2 = default(Texture2D[]);
		Texture2D[] array3 = default(Texture2D[]);
		if ((bool)preterrain1.rtp_script)
		{
			Type type = preterrain1.rtp_script.GetType();
			FieldInfo field = type.GetField("globalSettingsHolder");
			value = field.GetValue(preterrain1.rtp_script);
			Type type2 = value.GetType();
			field2 = type2.GetField("splats");
			field3 = type2.GetField("Bumps");
			field4 = type2.GetField("Heights");
			array = new Texture2D[preterrain1.splatPrototypes.Count];
			array2 = new Texture2D[preterrain1.splatPrototypes.Count];
			array3 = new Texture2D[preterrain1.splatPrototypes.Count];
		}
		List<SplatPrototype> list = new List<SplatPrototype>();
		for (int i = 0; i < preterrain1.splatPrototypes.Count; i++)
		{
			if ((bool)preterrain1.splatPrototypes[i].texture)
			{
				list.Add(new SplatPrototype());
				if (settings.colormap && i == 0)
				{
					list[i].texture = preterrain2.splatPrototypes[i].texture;
					list[i].normalMap = preterrain2.splatPrototypes[i].normalMap;
					list[i].tileSize = preterrain2.splatPrototypes[i].tileSize;
					list[i].tileOffset = preterrain2.splatPrototypes[i].tileOffset;
				}
				else
				{
					list[i].texture = preterrain1.splatPrototypes[i].texture;
					list[i].normalMap = preterrain1.splatPrototypes[i].normalMap;
					list[i].tileSize = preterrain1.splatPrototypes[i].tileSize;
					list[i].tileOffset = preterrain1.splatPrototypes[i].tileOffset;
				}
			}
			else
			{
				preterrain1.splatPrototypes.RemoveAt(i);
				i--;
			}
			if ((bool)preterrain1.rtp_script)
			{
				array[i] = preterrain1.splatPrototypes[i].texture;
				array2[i] = preterrain1.splatPrototypes[i].normal_texture;
				array3[i] = preterrain1.splatPrototypes[i].height_texture;
			}
		}
		preterrain2.terrain.terrainData.splatPrototypes = list.ToArray();
		if ((bool)preterrain1.rtp_script)
		{
			field2.SetValue(value, array);
			field3.SetValue(value, array2);
			field4.SetValue(value, array3);
		}
		if (RuntimeServices.EqualityOperator(preterrain1, masterTerrain))
		{
			loop_prelayer("(ssc)", 0, loop_inactive: true);
		}
	}

	public void set_colormap(bool active, bool all_parameters)
	{
		int num = 0;
		if (active)
		{
			float num2 = default(float);
			for (num = 0; num < terrains.Count; num++)
			{
				if (all_parameters)
				{
					terrains[num].add_splatprototype(0);
				}
				if ((bool)terrains[num].terrain)
				{
					Vector3 size = terrains[num].terrain.terrainData.size;
					num2 = size.x;
				}
				else
				{
					num2 = terrains[num].size.x;
				}
				if (terrains[num].splatPrototypes.Count > 0)
				{
					if (all_parameters)
					{
						terrains[num].splatPrototypes[0].texture = terrains[num].colormap.texture;
					}
					terrains[num].colormap.tileSize = new Vector2(num2, num2);
					terrains[num].splatPrototypes[0].tileSize = terrains[num].colormap.tileSize;
					terrains[num].splatPrototypes[0].tileOffset = terrains[num].colormap.tileOffset;
					if ((bool)terrains[num].splatPrototypes[0].texture)
					{
						set_terrain_splat_textures(terrains[num], terrains[num]);
					}
				}
			}
		}
		else
		{
			for (num = 0; num < terrains.Count; num++)
			{
				if (terrains[num].splatPrototypes.Count > 0)
				{
					terrains[num].colormap.texture = terrains[num].splatPrototypes[0].texture;
					terrains[num].erase_splatprototype(0);
					set_terrain_splat_textures(terrains[num], terrains[num]);
				}
			}
		}
		loop_colormap(active);
	}

	public void loop_colormap(bool active)
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				if (prelayers[i].layer[j].output != layer_output_enum.splat)
				{
					continue;
				}
				for (int k = 0; k < prelayers[i].layer[j].splat_output.splat.Count; k++)
				{
					if (prelayers[i].layer[j].splat_output.splat[k] == 0)
					{
						if (!active)
						{
							prelayers[i].layer[j].splat_output.splat_value.active[k] = false;
							continue;
						}
						prelayers[i].layer[j].splat_output.splat[k] = prelayers[i].layer[j].splat_output.splat[k] + 1;
						prelayers[i].layer[j].splat_output.splat_value.active[k] = true;
					}
					else if (!active)
					{
						prelayers[i].layer[j].splat_output.splat[k] = prelayers[i].layer[j].splat_output.splat[k] - 1;
					}
					else
					{
						prelayers[i].layer[j].splat_output.splat[k] = prelayers[i].layer[j].splat_output.splat[k] + 1;
					}
				}
			}
		}
	}

	public void get_all_terrain_splat_textures()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			get_terrain_splat_textures(terrains[i]);
			check_synchronous_terrain_textures(terrains[i]);
		}
	}

	public void get_terrain_splat_textures(terrain_class preterrain1)
	{
		if (!preterrain1.terrain)
		{
			return;
		}
		Texture2D[] array = default(Texture2D[]);
		Texture2D[] array2 = default(Texture2D[]);
		Texture2D[] array3 = default(Texture2D[]);
		if ((bool)preterrain1.rtp_script)
		{
			Type type = preterrain1.rtp_script.GetType();
			FieldInfo field = type.GetField("globalSettingsHolder");
			object value = field.GetValue(preterrain1.rtp_script);
			Type type2 = value.GetType();
			FieldInfo field2 = type2.GetField("splats");
			array = (field2.GetValue(value) as Texture2D[]);
			field2 = type2.GetField("Bumps");
			array2 = (field2.GetValue(value) as Texture2D[]);
			field2 = type2.GetField("Heights");
			array3 = (field2.GetValue(value) as Texture2D[]);
		}
		for (int i = 0; i < preterrain1.terrain.terrainData.splatPrototypes.Length; i++)
		{
			if (preterrain1.splatPrototypes.Count - 1 < i)
			{
				preterrain1.splatPrototypes.Add(new splatPrototype_class());
			}
			preterrain1.splatPrototypes[i].tileSize = preterrain1.terrain.terrainData.splatPrototypes[i].tileSize;
			preterrain1.splatPrototypes[i].tileOffset = preterrain1.terrain.terrainData.splatPrototypes[i].tileOffset;
			if (!preterrain1.rtp_script)
			{
				preterrain1.splatPrototypes[i].texture = preterrain1.terrain.terrainData.splatPrototypes[i].texture;
				preterrain1.splatPrototypes[i].normalMap = preterrain1.terrain.terrainData.splatPrototypes[i].normalMap;
			}
			else
			{
				preterrain1.splatPrototypes[i].texture = array[i];
				preterrain1.splatPrototypes[i].normal_texture = array2[i];
				preterrain1.splatPrototypes[i].height_texture = array3[i];
			}
		}
		int num = preterrain1.splatPrototypes.Count - preterrain1.terrain.terrainData.splatPrototypes.Length;
		for (int i = 0; i < num; i++)
		{
			preterrain1.splatPrototypes.RemoveAt(preterrain1.splatPrototypes.Count - 1);
		}
	}

	public void check_synchronous_terrains_textures()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			check_synchronous_terrain_textures(terrains[i]);
		}
	}

	public void check_synchronous_terrain_textures(terrain_class preterrain1)
	{
		check_synchronous_terrain_splat_textures(preterrain1);
	}

	public void check_synchronous_terrains_splat_textures()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			check_synchronous_terrain_splat_textures(terrains[i]);
		}
	}

	public void check_synchronous_terrain_splat_textures(terrain_class preterrain1)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		Texture2D[] array = default(Texture2D[]);
		Texture2D[] array2 = default(Texture2D[]);
		Texture2D[] array3 = default(Texture2D[]);
		if ((bool)preterrain1.rtp_script)
		{
			Type type = preterrain1.rtp_script.GetType();
			FieldInfo field = type.GetField("globalSettingsHolder");
			object value = field.GetValue(preterrain1.rtp_script);
			Type type2 = value.GetType();
			FieldInfo field2 = type2.GetField("splats");
			array = (field2.GetValue(value) as Texture2D[]);
			field2 = type2.GetField("Bumps");
			array2 = (field2.GetValue(value) as Texture2D[]);
			field2 = type2.GetField("Heights");
			array3 = (field2.GetValue(value) as Texture2D[]);
		}
		bool splat_synchronous = true;
		if (preterrain1.splatPrototypes.Count != preterrain1.terrain.terrainData.splatPrototypes.Length)
		{
			splat_synchronous = false;
		}
		else
		{
			for (int i = 0; i < preterrain1.splatPrototypes.Count; i++)
			{
				if (!preterrain1.rtp_script)
				{
					if (preterrain1.splatPrototypes[i].texture != preterrain1.terrain.terrainData.splatPrototypes[i].texture)
					{
						splat_synchronous = false;
						break;
					}
					if (preterrain1.splatPrototypes[i].normalMap != preterrain1.terrain.terrainData.splatPrototypes[i].normalMap)
					{
						splat_synchronous = false;
						break;
					}
					if (preterrain1.splatPrototypes[i].tileOffset != preterrain1.terrain.terrainData.splatPrototypes[i].tileOffset)
					{
						splat_synchronous = false;
						break;
					}
				}
				else
				{
					if (preterrain1.splatPrototypes[i].texture != array[i])
					{
						splat_synchronous = false;
						break;
					}
					if (preterrain1.splatPrototypes[i].normal_texture != array2[i])
					{
						splat_synchronous = false;
						break;
					}
					if (preterrain1.splatPrototypes[i].height_texture != array3[i])
					{
						splat_synchronous = false;
						break;
					}
				}
			}
		}
		preterrain1.splat_synchronous = splat_synchronous;
	}

	public void check_synchronous_terrains_color_textures()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			check_synchronous_terrain_color_textures(terrains[i]);
		}
	}

	public void check_synchronous_terrain_color_textures(terrain_class preterrain1)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		Texture2D[] array = default(Texture2D[]);
		if ((bool)preterrain1.rtp_script)
		{
			Type type = preterrain1.rtp_script.GetType();
			FieldInfo field = type.GetField("globalSettingsHolder");
			object value = field.GetValue(preterrain1.rtp_script);
			Type type2 = value.GetType();
			FieldInfo field2 = type2.GetField("splats");
			array = (field2.GetValue(value) as Texture2D[]);
			field2 = type2.GetField("Bumps");
			Texture2D[] array2 = field2.GetValue(value) as Texture2D[];
			field2 = type2.GetField("Heights");
			Texture2D[] array3 = field2.GetValue(value) as Texture2D[];
		}
		bool splat_synchronous = true;
		if (settings.color_splatPrototypes.Length != preterrain1.terrain.terrainData.splatPrototypes.Length)
		{
			splat_synchronous = false;
		}
		else
		{
			for (int i = 0; i < settings.color_splatPrototypes.Length; i++)
			{
				if (!preterrain1.rtp_script)
				{
					if (settings.color_splatPrototypes[i].texture != preterrain1.terrain.terrainData.splatPrototypes[i].texture)
					{
						splat_synchronous = false;
						break;
					}
					if (settings.color_splatPrototypes[i].tileOffset != preterrain1.terrain.terrainData.splatPrototypes[i].tileOffset)
					{
						splat_synchronous = false;
						break;
					}
				}
				else if (settings.color_splatPrototypes[i].texture != array[i])
				{
					splat_synchronous = false;
					break;
				}
			}
		}
		preterrain1.splat_synchronous = splat_synchronous;
	}

	public void check_synchronous_terrain_size(terrain_class preterrain1)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		bool size_synchronous = true;
		float x = preterrain1.size.x;
		Vector3 size = preterrain1.terrain.terrainData.size;
		if (x == size.x)
		{
			float y = preterrain1.size.y;
			Vector3 size2 = preterrain1.terrain.terrainData.size;
			if (y == size2.y)
			{
				float z = preterrain1.size.z;
				Vector3 size3 = preterrain1.terrain.terrainData.size;
				if (z == size3.z)
				{
					goto IL_00ab;
				}
			}
		}
		size_synchronous = false;
		goto IL_00ab;
		IL_00ab:
		preterrain1.size_synchronous = size_synchronous;
	}

	public void check_synchronous_terrain_resolutions(terrain_class preterrain1)
	{
		if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData)
		{
			bool resolutions_synchronous = true;
			if (preterrain1.heightmap_resolution != (float)preterrain1.terrain.terrainData.heightmapResolution || preterrain1.splatmap_resolution != (float)preterrain1.terrain.terrainData.alphamapResolution || preterrain1.detail_resolution != (float)preterrain1.terrain.terrainData.detailResolution || preterrain1.basemap_resolution != (float)preterrain1.terrain.terrainData.baseMapResolution)
			{
				resolutions_synchronous = false;
			}
			preterrain1.resolutions_synchronous = resolutions_synchronous;
		}
	}

	public void copy_terrain_splat(splatPrototype_class splatPrototype1, splatPrototype_class splatPrototype2)
	{
		splatPrototype2.texture = splatPrototype1.texture;
		splatPrototype2.tileSize_old = splatPrototype1.tileSize_old;
		splatPrototype2.tileOffset = splatPrototype1.tileOffset;
		splatPrototype2.normal_texture = splatPrototype1.normal_texture;
		splatPrototype2.normal_tileSize = splatPrototype1.normal_tileSize;
		splatPrototype2.height_texture = splatPrototype1.height_texture;
	}

	public void copy_terrain_splats(terrain_class preterrain1, terrain_class preterrain2)
	{
		for (int i = 0; i < preterrain1.splatPrototypes.Count; i++)
		{
			if (preterrain2.splatPrototypes.Count < preterrain1.splatPrototypes.Count)
			{
				preterrain2.splatPrototypes.Add(new splatPrototype_class());
			}
			copy_terrain_splat(preterrain1.splatPrototypes[i], preterrain2.splatPrototypes[i]);
		}
	}

	public void swap_terrain_splat(terrain_class preterrain1, int splat_number1, int splat_number2)
	{
		if (splat_number2 > -1 && splat_number2 < preterrain1.splatPrototypes.Count)
		{
			splatPrototype_class value = preterrain1.splatPrototypes[splat_number1];
			preterrain1.splatPrototypes[splat_number1] = preterrain1.splatPrototypes[splat_number2];
			preterrain1.splatPrototypes[splat_number2] = value;
		}
	}

	public void set_all_terrain_trees(terrain_class preterrain1)
	{
		set_terrain_trees(preterrain1);
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].terrain.terrainData.treePrototypes = preterrain1.terrain.terrainData.treePrototypes;
				get_terrain_trees(terrains[i]);
				terrains[i].color_terrain = new Color(0.5f, 1f, 0.5f);
				check_synchronous_terrain_trees(terrains[i]);
			}
		}
	}

	public void set_terrain_trees(terrain_class preterrain1)
	{
		List<TreePrototype> list = new List<TreePrototype>();
		for (int i = 0; i < preterrain1.treePrototypes.Count; i++)
		{
			if ((bool)preterrain1.treePrototypes[i].prefab)
			{
				list.Add(new TreePrototype());
				list[i].prefab = preterrain1.treePrototypes[i].prefab;
				list[i].bendFactor = preterrain1.treePrototypes[i].bendFactor;
			}
		}
		preterrain1.terrain.terrainData.treePrototypes = list.ToArray();
	}

	public void get_all_terrain_trees()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			get_terrain_trees(terrains[i]);
			check_synchronous_terrain_trees(terrains[i]);
		}
	}

	public void get_terrain_trees(terrain_class preterrain1)
	{
		preterrain1.treePrototypes.Clear();
		for (int i = 0; i < preterrain1.terrain.terrainData.treePrototypes.Length; i++)
		{
			preterrain1.treePrototypes.Add(new treePrototype_class());
			preterrain1.treePrototypes[i].prefab = preterrain1.terrain.terrainData.treePrototypes[i].prefab;
			preterrain1.treePrototypes[i].bendFactor = preterrain1.terrain.terrainData.treePrototypes[i].bendFactor;
		}
	}

	public void check_synchronous_terrain_trees(terrain_class preterrain1)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		bool tree_synchronous = true;
		if (preterrain1.treePrototypes.Count != preterrain1.terrain.terrainData.treePrototypes.Length)
		{
			tree_synchronous = false;
		}
		else
		{
			for (int i = 0; i < preterrain1.treePrototypes.Count; i++)
			{
				if (preterrain1.treePrototypes[i].prefab != preterrain1.terrain.terrainData.treePrototypes[i].prefab)
				{
					tree_synchronous = false;
					break;
				}
				if (preterrain1.treePrototypes[i].bendFactor != preterrain1.terrain.terrainData.treePrototypes[i].bendFactor)
				{
					tree_synchronous = false;
					break;
				}
			}
		}
		preterrain1.tree_synchronous = tree_synchronous;
	}

	public void copy_terrain_tree(treePrototype_class treePrototype1, treePrototype_class treePrototype2)
	{
		treePrototype2.prefab = treePrototype1.prefab;
		treePrototype2.bendFactor = treePrototype1.bendFactor;
	}

	public void copy_terrain_trees(terrain_class preterrain1, terrain_class preterrain2)
	{
		for (int i = 0; i < preterrain1.treePrototypes.Count; i++)
		{
			if (preterrain2.treePrototypes.Count < preterrain1.treePrototypes.Count)
			{
				preterrain2.treePrototypes.Add(new treePrototype_class());
			}
			copy_terrain_tree(preterrain1.treePrototypes[i], preterrain2.treePrototypes[i]);
		}
	}

	public void swap_terrain_tree(terrain_class preterrain1, int tree_number1, int tree_number2)
	{
		if (tree_number2 > -1 && tree_number2 < preterrain1.treePrototypes.Count)
		{
			treePrototype_class value = preterrain1.treePrototypes[tree_number1];
			preterrain1.treePrototypes[tree_number1] = preterrain1.treePrototypes[tree_number2];
			preterrain1.treePrototypes[tree_number2] = value;
		}
	}

	public void set_terrain_details(terrain_class preterrain1)
	{
		List<DetailPrototype> list = new List<DetailPrototype>();
		for (int i = 0; i < preterrain1.detailPrototypes.Count; i++)
		{
			if ((bool)preterrain1.detailPrototypes[i].prototype || (bool)preterrain1.detailPrototypes[i].prototypeTexture)
			{
				list.Add(new DetailPrototype());
				list[i].renderMode = preterrain1.detailPrototypes[i].renderMode;
				if (preterrain1.detailPrototypes[i].usePrototypeMesh)
				{
					list[i].usePrototypeMesh = true;
					list[i].prototype = preterrain1.detailPrototypes[i].prototype;
					list[i].minWidth = -1f;
					list[i].maxWidth = preterrain1.detailPrototypes[i].maxWidth + 1f;
					list[i].minHeight = -1f;
					list[i].maxHeight = preterrain1.detailPrototypes[i].maxHeight + 1f;
				}
				else
				{
					list[i].prototypeTexture = preterrain1.detailPrototypes[i].prototypeTexture;
					list[i].minWidth = preterrain1.detailPrototypes[i].minWidth;
					list[i].maxWidth = preterrain1.detailPrototypes[i].maxWidth;
					list[i].minHeight = preterrain1.detailPrototypes[i].minHeight;
					list[i].maxHeight = preterrain1.detailPrototypes[i].maxHeight;
				}
				list[i].noiseSpread = preterrain1.detailPrototypes[i].noiseSpread;
				list[i].healthyColor = preterrain1.detailPrototypes[i].healthyColor;
				list[i].dryColor = preterrain1.detailPrototypes[i].dryColor;
				list[i].bendFactor = preterrain1.detailPrototypes[i].bendFactor;
			}
		}
		preterrain1.terrain.terrainData.detailPrototypes = list.ToArray();
		preterrain1.detail_scale = 1f;
	}

	public void copy_terrain_detail(detailPrototype_class detailPrototype1, detailPrototype_class detailPrototype2)
	{
		detailPrototype2.prototype = detailPrototype1.prototype;
		detailPrototype2.prototypeTexture = detailPrototype1.prototypeTexture;
		detailPrototype2.minWidth = detailPrototype1.minWidth;
		detailPrototype2.maxWidth = detailPrototype1.maxWidth;
		detailPrototype2.minHeight = detailPrototype1.minHeight;
		detailPrototype2.maxHeight = detailPrototype1.maxHeight;
		detailPrototype2.noiseSpread = detailPrototype1.noiseSpread;
		detailPrototype2.healthyColor = detailPrototype1.healthyColor;
		detailPrototype2.dryColor = detailPrototype1.dryColor;
		detailPrototype2.renderMode = detailPrototype1.renderMode;
		detailPrototype2.bendFactor = detailPrototype1.bendFactor;
	}

	public void copy_terrain_details(terrain_class preterrain1, terrain_class preterrain2)
	{
		for (int i = 0; i < preterrain1.detailPrototypes.Count; i++)
		{
			if (preterrain2.detailPrototypes.Count < preterrain1.detailPrototypes.Count)
			{
				preterrain2.detailPrototypes.Add(new detailPrototype_class());
			}
			copy_terrain_detail(preterrain1.detailPrototypes[i], preterrain2.detailPrototypes[i]);
		}
	}

	public void swap_terrain_detail(terrain_class preterrain1, int detail_number1, int detail_number2)
	{
		if (detail_number2 > -1 && detail_number2 < preterrain1.detailPrototypes.Count)
		{
			detailPrototype_class value = preterrain1.detailPrototypes[detail_number1];
			preterrain1.detailPrototypes[detail_number1] = preterrain1.detailPrototypes[detail_number2];
			preterrain1.detailPrototypes[detail_number2] = value;
		}
	}

	public void get_all_terrain_details()
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			get_terrain_details(terrains[i]);
			check_synchronous_terrain_detail(terrains[i]);
		}
	}

	public void get_terrain_details(terrain_class preterrain1)
	{
		for (int i = 0; i < preterrain1.terrain.terrainData.detailPrototypes.Length; i++)
		{
			if (preterrain1.detailPrototypes.Count < preterrain1.terrain.terrainData.detailPrototypes.Length)
			{
				preterrain1.detailPrototypes.Add(new detailPrototype_class());
			}
			else if (preterrain1.detailPrototypes.Count > preterrain1.terrain.terrainData.detailPrototypes.Length)
			{
				preterrain1.detailPrototypes.RemoveAt(i);
			}
			if (preterrain1.detailPrototypes[i].usePrototypeMesh)
			{
				preterrain1.detailPrototypes[i].prototype = preterrain1.terrain.terrainData.detailPrototypes[i].prototype;
				preterrain1.detailPrototypes[i].minWidth = preterrain1.terrain.terrainData.detailPrototypes[i].minWidth;
				preterrain1.detailPrototypes[i].maxWidth = preterrain1.terrain.terrainData.detailPrototypes[i].maxWidth - 1f;
				preterrain1.detailPrototypes[i].minHeight = preterrain1.terrain.terrainData.detailPrototypes[i].minHeight;
				preterrain1.detailPrototypes[i].maxHeight = preterrain1.terrain.terrainData.detailPrototypes[i].maxHeight - 1f;
			}
			else
			{
				preterrain1.detailPrototypes[i].prototypeTexture = preterrain1.terrain.terrainData.detailPrototypes[i].prototypeTexture;
				preterrain1.detailPrototypes[i].minWidth = preterrain1.terrain.terrainData.detailPrototypes[i].minWidth;
				preterrain1.detailPrototypes[i].maxWidth = preterrain1.terrain.terrainData.detailPrototypes[i].maxWidth;
				preterrain1.detailPrototypes[i].minHeight = preterrain1.terrain.terrainData.detailPrototypes[i].minHeight;
				preterrain1.detailPrototypes[i].maxHeight = preterrain1.terrain.terrainData.detailPrototypes[i].maxHeight;
			}
			preterrain1.detailPrototypes[i].noiseSpread = preterrain1.terrain.terrainData.detailPrototypes[i].noiseSpread;
			preterrain1.detailPrototypes[i].healthyColor = preterrain1.terrain.terrainData.detailPrototypes[i].healthyColor;
			preterrain1.detailPrototypes[i].dryColor = preterrain1.terrain.terrainData.detailPrototypes[i].dryColor;
			preterrain1.detailPrototypes[i].renderMode = preterrain1.terrain.terrainData.detailPrototypes[i].renderMode;
			preterrain1.detailPrototypes[i].bendFactor = preterrain1.terrain.terrainData.detailPrototypes[i].bendFactor;
		}
		if (preterrain1.terrain.terrainData.detailPrototypes.Length == 0)
		{
			preterrain1.detailPrototypes.Clear();
		}
	}

	public void check_synchronous_terrain_detail(terrain_class preterrain1)
	{
		if (!preterrain1.terrain || !preterrain1.terrain.terrainData)
		{
			return;
		}
		bool detail_synchronous = true;
		if (preterrain1.detailPrototypes.Count != preterrain1.terrain.terrainData.detailPrototypes.Length)
		{
			detail_synchronous = false;
		}
		else
		{
			for (int i = 0; i < preterrain1.detailPrototypes.Count; i++)
			{
				if (preterrain1.detailPrototypes[i].usePrototypeMesh)
				{
					if (preterrain1.detailPrototypes[i].prototype != preterrain1.terrain.terrainData.detailPrototypes[i].prototype)
					{
						detail_synchronous = false;
						break;
					}
					if (preterrain1.detailPrototypes[i].maxWidth != preterrain1.terrain.terrainData.detailPrototypes[i].maxWidth - 1f)
					{
						detail_synchronous = false;
						break;
					}
					if (preterrain1.detailPrototypes[i].maxHeight != preterrain1.terrain.terrainData.detailPrototypes[i].maxHeight - 1f)
					{
						detail_synchronous = false;
						break;
					}
				}
				else
				{
					if (preterrain1.detailPrototypes[i].prototypeTexture != preterrain1.terrain.terrainData.detailPrototypes[i].prototypeTexture)
					{
						detail_synchronous = false;
						break;
					}
					if (preterrain1.detailPrototypes[i].minWidth != preterrain1.terrain.terrainData.detailPrototypes[i].minWidth)
					{
						detail_synchronous = false;
						break;
					}
					if (preterrain1.detailPrototypes[i].maxWidth != preterrain1.terrain.terrainData.detailPrototypes[i].maxWidth)
					{
						detail_synchronous = false;
						break;
					}
					if (preterrain1.detailPrototypes[i].minHeight != preterrain1.terrain.terrainData.detailPrototypes[i].minHeight)
					{
						detail_synchronous = false;
						break;
					}
					if (preterrain1.detailPrototypes[i].maxHeight != preterrain1.terrain.terrainData.detailPrototypes[i].maxHeight)
					{
						detail_synchronous = false;
						break;
					}
				}
				if (preterrain1.detailPrototypes[i].noiseSpread != preterrain1.terrain.terrainData.detailPrototypes[i].noiseSpread)
				{
					detail_synchronous = false;
					break;
				}
				if (preterrain1.detailPrototypes[i].healthyColor != preterrain1.terrain.terrainData.detailPrototypes[i].healthyColor)
				{
					detail_synchronous = false;
					break;
				}
				if (preterrain1.detailPrototypes[i].dryColor != preterrain1.terrain.terrainData.detailPrototypes[i].dryColor)
				{
					detail_synchronous = false;
					break;
				}
				if (preterrain1.detailPrototypes[i].renderMode != preterrain1.terrain.terrainData.detailPrototypes[i].renderMode)
				{
					detail_synchronous = false;
					break;
				}
				if (preterrain1.detailPrototypes[i].bendFactor != preterrain1.terrain.terrainData.detailPrototypes[i].bendFactor)
				{
					detail_synchronous = false;
					break;
				}
			}
		}
		preterrain1.detail_synchronous = detail_synchronous;
	}

	public void change_terrain_detail_scale(terrain_class preterrain1)
	{
		if (preterrain1.terrain.terrainData.detailPrototypes.Length >= preterrain1.detailPrototypes.Count)
		{
			for (int i = 0; i < preterrain1.detailPrototypes.Count; i++)
			{
				preterrain1.detailPrototypes[i].minWidth = preterrain1.terrain.terrainData.detailPrototypes[i].minWidth * preterrain1.detail_scale;
				preterrain1.detailPrototypes[i].maxWidth = preterrain1.terrain.terrainData.detailPrototypes[i].maxWidth * preterrain1.detail_scale;
				preterrain1.detailPrototypes[i].minHeight = preterrain1.terrain.terrainData.detailPrototypes[i].minHeight * preterrain1.detail_scale;
				preterrain1.detailPrototypes[i].maxHeight = preterrain1.terrain.terrainData.detailPrototypes[i].maxHeight * preterrain1.detail_scale;
			}
		}
	}

	public void set_all_terrain_details(terrain_class preterrain1)
	{
		set_terrain_details(preterrain1);
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				terrains[i].terrain.terrainData.detailPrototypes = preterrain1.terrain.terrainData.detailPrototypes;
				get_terrain_details(terrains[i]);
				terrains[i].color_terrain = new Color(0.5f, 1f, 0.5f);
				check_synchronous_terrain_detail(terrains[i]);
			}
		}
	}

	public Color convert_float_to_color(float value_float)
	{
		byte[] array = new byte[4];
		Color result = default(Color);
		float num = default(float);
		array = BitConverter.GetBytes(value_float);
		num = (int)array[0];
		result[0] = num / 255f;
		num = (int)array[1];
		result[1] = num / 255f;
		num = (int)array[2];
		result[2] = num / 255f;
		num = (int)array[3];
		result[3] = num / 255f;
		return result;
	}

	public float convert_color_to_float(Color color)
	{
		return BitConverter.ToSingle(new byte[4]
		{
			(byte)(color[0] * 255f),
			(byte)(color[1] * 255f),
			(byte)(color[2] * 255f),
			(byte)(color[3] * 255f)
		}, 0);
	}

	public float get_scale_from_image(Texture2D image)
	{
		Color color = default(Color);
		Color color2 = default(Color);
		float num = default(float);
		color[0] = image.GetPixel(0, 0)[3];
		color[1] = image.GetPixel(1, 0)[3];
		color[2] = image.GetPixel(2, 0)[3];
		color[3] = image.GetPixel(3, 0)[3];
		return convert_color_to_float(color);
	}

	public Vector2 calc_rotation_pixel(float x, float y, float xx, float yy, float rotation)
	{
		float num = x - xx;
		float num2 = y - yy;
		float num3 = Mathf.Sqrt(num * num + num2 * num2);
		if (num3 != 0f)
		{
			num /= num3;
			num2 /= num3;
		}
		float num4 = Mathf.Acos(num);
		if (!(num2 >= 0f))
		{
			num4 = (float)Math.PI * 2f - num4;
		}
		num4 -= rotation * ((float)Math.PI / 180f);
		num = Mathf.Cos(num4) * num3;
		num2 = Mathf.Sin(num4) * num3;
		Vector2 result = default(Vector2);
		result.x = num + xx;
		result.y = num2 + yy;
		return result;
	}

	public prelayer_class copy_prelayer(prelayer_class prelayer1, object copy_filter)
	{
		prelayer_class prelayer_class = null;
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.prelayer = prelayer1;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		prelayer_class = save_template.prelayer;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		if (RuntimeServices.ToBool(copy_filter))
		{
			for (int i = 0; i < prelayer1.layer.Count; i++)
			{
				prelayer_class.layer[i].prefilter = copy_prefilter(prelayer1.layer[i].prefilter);
			}
		}
		return prelayer_class;
	}

	public prelayer_class copy_layergroup(prelayer_class prelayer1, int description_number, bool copy_filter)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		prelayer_class prelayer_class = null;
		save_template.prelayer = new prelayer_class(0, 0);
		for (int i = 0; i < prelayer1.predescription.description[description_number].layer_index.Count; i++)
		{
			save_template.prelayer.layer.Insert(i, new layer_class());
			save_template.prelayer.layer[i] = copy_layer(prelayer1.layer[prelayer1.predescription.description[description_number].layer_index[i]], copy_filter: false, loop: false);
		}
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		prelayer_class = save_template.prelayer;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		if (copy_filter)
		{
			for (int i = 0; i < prelayer1.layer.Count; i++)
			{
				prelayer_class.layer[i].prefilter = copy_prefilter(prelayer1.layer[i].prefilter);
				for (int j = 0; j < prelayer1.layer[i].tree_output.tree.Count; j++)
				{
					prelayer_class.layer[i].tree_output.tree[j].prefilter = copy_prefilter(prelayer1.layer[i].tree_output.tree[j].prefilter);
				}
			}
		}
		return prelayer_class;
	}

	public layer_class copy_layer(layer_class layer, bool copy_filter, bool loop)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.layer = layer;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		layer = save_template.layer;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		if (copy_filter)
		{
			save_template.layer.prefilter = copy_prefilter(layer.prefilter);
			for (int i = 0; i < layer.tree_output.tree.Count; i++)
			{
				save_template.layer.tree_output.tree[i].prefilter = copy_prefilter(layer.tree_output.tree[i].prefilter);
			}
		}
		layer.text_placed = string.Empty;
		if (loop)
		{
			loop_layer(layer, 1);
		}
		layer.swap_text = "S";
		layer.swap_select = false;
		layer.copy_select = false;
		layer.color_layer = new Color(2f, 2f, 2f, 1f);
		return layer;
	}

	public void save_loop_layer(int prelayer_number, int layer_number, int prelayer_number_save, int layer_number_save, save_template script3)
	{
		script3.prelayers[prelayer_number_save].layer[layer_number_save].swap_text = "S";
		script3.prelayers[prelayer_number_save].layer[layer_number_save].swap_select = false;
		script3.prelayers[prelayer_number_save].layer[layer_number_save].copy_select = false;
		for (int i = 0; i < prelayers[prelayer_number].layer[layer_number].prefilter.filter_index.Count; i++)
		{
			script3.filters.Add(copy_filter(filter[prelayers[prelayer_number].layer[layer_number].prefilter.filter_index[i]], copy_subfilter: false));
			script3.prelayers[prelayer_number_save].layer[layer_number_save].prefilter.filter_index[i] = script3.filters.Count - 1;
			for (int j = 0; j < filter[prelayers[prelayer_number].layer[layer_number].prefilter.filter_index[i]].presubfilter.subfilter_index.Count; j++)
			{
				script3.subfilters.Add(copy_subfilter(subfilter[filter[prelayers[prelayer_number].layer[layer_number].prefilter.filter_index[i]].presubfilter.subfilter_index[j]]));
				script3.filters[script3.filters.Count - 1].presubfilter.subfilter_index[j] = script3.subfilters.Count - 1;
			}
		}
		for (int k = 0; k < prelayers[prelayer_number].layer[layer_number].tree_output.tree.Count; k++)
		{
			for (int i = 0; i < prelayers[prelayer_number].layer[layer_number].tree_output.tree[k].prefilter.filter_index.Count; i++)
			{
				script3.filters.Add(copy_filter(filter[prelayers[prelayer_number].layer[layer_number].tree_output.tree[k].prefilter.filter_index[i]], copy_subfilter: false));
				script3.prelayers[prelayer_number_save].layer[layer_number_save].tree_output.tree[k].prefilter.filter_index[i] = script3.filters.Count - 1;
				for (int j = 0; j < filter[prelayers[prelayer_number].layer[layer_number].tree_output.tree[k].prefilter.filter_index[i]].presubfilter.subfilter_index.Count; j++)
				{
					script3.subfilters.Add(copy_subfilter(subfilter[filter[prelayers[prelayer_number].layer[layer_number].tree_output.tree[k].prefilter.filter_index[i]].presubfilter.subfilter_index[j]]));
					script3.filters[script3.filters.Count - 1].presubfilter.subfilter_index[j] = script3.subfilters.Count - 1;
				}
			}
		}
		for (int l = 0; l < prelayers[prelayer_number].layer[layer_number].object_output.@object.Count; l++)
		{
			if (prelayers[prelayer_number].layer[layer_number].object_output.@object[l].prelayer_created)
			{
				script3.prelayers.Add(copy_prelayer(prelayers[prelayers[prelayer_number].layer[layer_number].object_output.@object[l].prelayer_index], false));
				script3.prelayers[prelayer_number_save].layer[layer_number_save].object_output.@object[l].prelayer_index = script3.prelayers.Count - 1;
				for (int m = 0; m < prelayers[prelayers[prelayer_number].layer[layer_number].object_output.@object[l].prelayer_index].layer.Count; m++)
				{
					save_loop_layer(prelayers[prelayer_number].layer[layer_number].object_output.@object[l].prelayer_index, m, prelayer_number_save + 1, m, script3);
				}
			}
		}
	}

	public void load_loop_layer(int prelayer_number, int layer_number, int prelayer_number_load, int layer_number_load, save_template script3)
	{
		for (int i = 0; i < script3.prelayers[prelayer_number_load].layer[layer_number_load].prefilter.filter_index.Count; i++)
		{
			filter.Add(copy_filter(script3.filters[script3.prelayers[prelayer_number_load].layer[layer_number_load].prefilter.filter_index[i]], copy_subfilter: false));
			prelayers[prelayer_number].layer[layer_number].prefilter.filter_index[i] = filter.Count - 1;
			for (int j = 0; j < filter[filter.Count - 1].presubfilter.subfilter_index.Count; j++)
			{
				subfilter.Add(copy_subfilter(script3.subfilters[filter[filter.Count - 1].presubfilter.subfilter_index[j]]));
				filter[filter.Count - 1].presubfilter.subfilter_index[j] = subfilter.Count - 1;
			}
		}
		for (int k = 0; k < script3.prelayers[prelayer_number_load].layer[layer_number_load].tree_output.tree.Count; k++)
		{
			for (int i = 0; i < script3.prelayers[prelayer_number_load].layer[layer_number_load].tree_output.tree[k].prefilter.filter_index.Count; i++)
			{
				filter.Add(copy_filter(script3.filters[script3.prelayers[prelayer_number_load].layer[layer_number_load].tree_output.tree[k].prefilter.filter_index[i]], copy_subfilter: false));
				prelayers[prelayer_number].layer[layer_number].tree_output.tree[k].prefilter.filter_index[i] = filter.Count - 1;
				for (int j = 0; j < filter[filter.Count - 1].presubfilter.subfilter_index.Count; j++)
				{
					subfilter.Add(copy_subfilter(script3.subfilters[filter[filter.Count - 1].presubfilter.subfilter_index[j]]));
					filter[filter.Count - 1].presubfilter.subfilter_index[j] = subfilter.Count - 1;
				}
			}
		}
		for (int l = 0; l < script3.prelayers[prelayer_number_load].layer[layer_number_load].object_output.@object.Count; l++)
		{
			if (script3.prelayers[prelayer_number_load].layer[layer_number_load].object_output.@object[l].prelayer_created)
			{
				prelayers.Add(copy_prelayer(script3.prelayers[script3.prelayers[prelayer_number_load].layer[layer_number_load].object_output.@object[l].prelayer_index], false));
				prelayers[prelayer_number].layer[layer_number].object_output.@object[l].prelayer_index = prelayers.Count - 1;
				for (int m = 0; m < script3.prelayers[script3.prelayers[prelayer_number_load].layer[layer_number_load].object_output.@object[l].prelayer_index].layer.Count; m++)
				{
					load_loop_layer(prelayers.Count - 1, m, script3.prelayers[prelayer_number_load].layer[layer_number_load].object_output.@object[l].prelayer_index, m, script3);
				}
			}
		}
	}

	public void copy_description(prelayer_class prelayer1, int description_number, prelayer_class target_prelayer, int target_description_number)
	{
		target_prelayer.predescription.description[target_description_number].text = prelayer1.predescription.description[description_number].text + "#";
		target_prelayer.predescription.description[target_description_number].edit = prelayer1.predescription.description[description_number].edit;
		target_prelayer.predescription.description[target_description_number].layers_active = prelayer1.predescription.description[description_number].layers_active;
		int num = get_layer_position(0, target_description_number, target_prelayer);
		int count = prelayer1.predescription.description[description_number].layer_index.Count;
		for (int i = 0; i < count; i++)
		{
			add_layer(target_prelayer, num, layer_output_enum.color, target_description_number, 0, new_filter: false, count_layer: false, custom: false);
			target_prelayer.layer[num] = copy_layer(prelayer1.layer[prelayer1.predescription.description[description_number].layer_index[count - 1 - i]], copy_filter: true, loop: true);
		}
		count_layers();
	}

	public prefilter_class copy_prefilter(prefilter_class prefilter)
	{
		prefilter_class prefilter_class = new prefilter_class();
		for (int i = 0; i < prefilter.filter_index.Count; i++)
		{
			filter.Add(copy_filter(filter[prefilter.filter_index[i]], copy_subfilter: true));
			prefilter_class.filter_index.Add(filter.Count - 1);
		}
		prefilter_class.set_filter_text();
		return prefilter_class;
	}

	public filter_class copy_filter(filter_class filter, bool copy_subfilter)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.filter = filter;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		filter = save_template.filter;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		if (copy_subfilter)
		{
			for (int i = default(int); i < filter.presubfilter.subfilter_index.Count; i++)
			{
				subfilter.Add(this.copy_subfilter(subfilter[filter.presubfilter.subfilter_index[i]]));
				filter.presubfilter.subfilter_index[i] = subfilter.Count - 1;
			}
		}
		for (int j = 0; j < filter.preimage.precolor_range.color_range.Count; j++)
		{
			filter.preimage.precolor_range.color_range[j].swap_text = "S";
			filter.preimage.precolor_range.color_range[j].swap_select = false;
			filter.preimage.precolor_range.color_range[j].copy_select = false;
		}
		filter.swap_text = "S";
		filter.swap_select = false;
		filter.copy_select = false;
		filter.prerandom_curve.curve_text = "Curve";
		filter.precurve_x_left.curve_text = "Curve";
		filter.precurve_x_right.curve_text = "Curve";
		filter.precurve_z_left.curve_text = "Curve";
		filter.precurve_z_right.curve_text = "Curve";
		filter.color_filter = new Color(2f, 2f, 2f, 1f);
		return filter;
	}

	public subfilter_class copy_subfilter(subfilter_class subfilter)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.subfilter = subfilter;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		subfilter = save_template.subfilter;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		subfilter.swap_text = "S";
		subfilter.swap_select = false;
		subfilter.copy_select = false;
		for (int i = 0; i < subfilter.preimage.precolor_range.color_range.Count; i++)
		{
			subfilter.preimage.precolor_range.color_range[i].swap_text = "S";
			subfilter.preimage.precolor_range.color_range[i].swap_select = false;
			subfilter.preimage.precolor_range.color_range[i].copy_select = false;
		}
		subfilter.color_subfilter = new Color(2f, 2f, 2f, 1f);
		return subfilter;
	}

	public terrain_class copy_terrain(terrain_class preterrain1)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.preterrain = preterrain1;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		preterrain1 = save_template.preterrain;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		return preterrain1;
	}

	public splat_custom_class copy_splat_custom(splat_custom_class custom_splat1)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.splat_custom = custom_splat1;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		custom_splat1 = save_template.splat_custom;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		return custom_splat1;
	}

	public Terrain copy_terrain2(Terrain terrain1)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.terrain = terrain1;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		terrain1 = save_template.terrain;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		return terrain1;
	}

	public animation_curve_class copy_animation_curve(animation_curve_class animation_curve)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.animation_curve = animation_curve;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		animation_curve = save_template.animation_curve;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		return animation_curve;
	}

	public color_range_class copy_color_range(color_range_class color_range)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.color_range = color_range;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		color_range = save_template.color_range;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		color_range.swap_text = "S";
		color_range.swap_select = false;
		color_range.copy_select = false;
		return color_range;
	}

	public precolor_range_class copy_precolor_range(precolor_range_class precolor_range)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.precolor_range = precolor_range;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		precolor_range = save_template.precolor_range;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		return precolor_range;
	}

	public tree_class copy_tree(tree_class tree)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.tree = tree;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		tree = save_template.tree;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		for (int i = 0; i < tree.prefilter.filter_index.Count; i++)
		{
			filter.Add(copy_filter(filter[tree.prefilter.filter_index[i]], copy_subfilter: true));
			tree.prefilter.filter_index[i] = filter.Count - 1;
		}
		tree.placed = 0;
		tree.swap_select = false;
		tree.copy_select = false;
		tree.swap_text = "S";
		return tree;
	}

	public object_class copy_object(object_class object1)
	{
		GameObject gameObject = new GameObject();
		save_template save_template = (save_template)gameObject.AddComponent(typeof(save_template));
		save_template.@object = object1;
		GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject);
		UnityEngine.Object.DestroyImmediate(gameObject);
		save_template = (save_template)gameObject2.GetComponent(typeof(save_template));
		object1 = save_template.@object;
		UnityEngine.Object.DestroyImmediate(gameObject2);
		object1.color_object = new Color(2f, 2f, 2f, 1f);
		object1.swap_text = "S";
		object1.swap_select = false;
		object1.copy_select = false;
		object1.placed = 0;
		return object1;
	}

	public int check_terrains_same_resolution()
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < terrains.Count)
			{
				if (!terrains[num].terrain)
				{
					result = -2;
					break;
				}
				if (!terrains[num].terrain.terrainData)
				{
					result = -2;
					break;
				}
				if (terrains[num].terrain.terrainData.heightmapResolution != terrains[0].terrain.terrainData.heightmapResolution)
				{
					result = -1;
					break;
				}
				num++;
				continue;
			}
			result = 1;
			break;
		}
		return result;
	}

	public bool stitch_terrains(float border_influence)
	{
		float num = Mathf.Round(border_influence / terrains[0].heightmap_conversion.x);
		float num2 = Mathf.Round(border_influence / terrains[0].heightmap_conversion.y);
		int result;
		if (!(border_influence >= terrains[0].heightmap_conversion.x * 1.5f))
		{
			result = 0;
		}
		else
		{
			float num3 = stitch_tool_strength;
			int num4 = default(int);
			int num5 = default(int);
			int num6 = default(int);
			float num7 = default(float);
			float num8 = default(float);
			float[,] array = null;
			float[,] array2 = null;
			float num9 = default(float);
			float num10 = default(float);
			float num11 = default(float);
			float num12 = default(float);
			float num13 = default(float);
			float num14 = default(float);
			float num15 = default(float);
			float num16 = default(float);
			float num17 = default(float);
			float num18 = default(float);
			float num19 = default(float);
			for (int i = 0; i < terrains.Count; i++)
			{
				num5 = -1;
				num6 = -1;
				for (num4 = 0; num4 < terrains.Count; num4++)
				{
					if (num4 != i)
					{
						ref Rect rect = ref terrains[num4].rect;
						Vector2 center = terrains[i].rect.center;
						if (rect.Contains(new Vector2(center.x, terrains[i].rect.yMax + terrains[i].heightmap_conversion.y)) && num5 == -1)
						{
							num5 = num4;
						}
						ref Rect rect2 = ref terrains[num4].rect;
						float x = terrains[i].rect.xMin - terrains[i].heightmap_conversion.x;
						Vector2 center2 = terrains[i].rect.center;
						if (rect2.Contains(new Vector2(x, center2.y)) && num6 == -1)
						{
							num6 = num4;
						}
					}
				}
				if (num5 != -1)
				{
					array = terrains[i].terrain.terrainData.GetHeights(0, (int)(terrains[i].heightmap_resolution - num2), (int)terrains[i].heightmap_resolution, (int)num2);
					array2 = terrains[num5].terrain.terrainData.GetHeights(0, 0, (int)terrains[i].heightmap_resolution, (int)num2);
					for (int j = 0; (float)j < terrains[i].heightmap_resolution; j++)
					{
						num12 = array[0, j];
						num13 = array2[(int)(num2 - 1f), j];
						for (num8 = 0f; num8 < num2 - 1f; num8 += 1f)
						{
							if (num8 == 0f)
							{
								num10 = array[(int)(num2 - num8 - 1f), j];
								num11 = array2[(int)num8, j];
								num9 = (num12 + num13) / 2f;
								num14 = (num12 - num9) / (num2 - 1f);
								num15 = (num13 - num9) / (num2 - 1f);
								array[(int)(num2 - num8 - 1f), j] = num9;
								array2[(int)num8, j] = num9;
							}
							else
							{
								array[(int)(num2 - num8 - 1f), j] = num9 + num14 * num8;
								array2[(int)num8, j] = num9 + num15 * num8;
							}
						}
					}
					terrains[i].terrain.terrainData.SetHeights(0, (int)(terrains[i].heightmap_resolution - num2), array);
					terrains[num5].terrain.terrainData.SetHeights(0, 0, array2);
				}
				if (num6 != -1)
				{
					array = terrains[i].terrain.terrainData.GetHeights(0, 0, (int)num, (int)terrains[i].heightmap_resolution);
					array2 = terrains[num6].terrain.terrainData.GetHeights((int)(terrains[i].heightmap_resolution - num), 0, (int)num, (int)terrains[i].heightmap_resolution);
					for (int k = 0; (float)k < terrains[i].heightmap_resolution; k++)
					{
						num12 = array[k, (int)(num - 1f)];
						num13 = array2[k, 0];
						for (num7 = 0f; num7 < num - 1f; num7 += 1f)
						{
							if (num7 == 0f)
							{
								num10 = array[k, (int)num7];
								num11 = array2[k, (int)(num - num7 - 1f)];
								num9 = (num12 + num13) / 2f;
								num14 = (num12 - num9) / (num - 1f);
								num15 = (num13 - num9) / (num - 1f);
								array[k, (int)num7] = num9;
								array2[k, (int)(num - num7 - 1f)] = num9;
							}
							else
							{
								array[k, (int)num7] = num9 + num14 * num7;
								array2[k, (int)(num - num7 - 1f)] = num9 + num15 * num7;
							}
						}
					}
					terrains[i].terrain.terrainData.SetHeights(0, 0, array);
					terrains[num6].terrain.terrainData.SetHeights((int)(terrains[i].heightmap_resolution - num), 0, array2);
				}
				if (!(terrains[i].color_terrain[0] >= 1.5f))
				{
					terrains[i].color_terrain = terrains[i].color_terrain + new Color(0.5f, 0.5f, 1f, 0.5f);
				}
			}
			result = 1;
		}
		return (byte)result != 0;
	}

	public void stitch_splatmap()
	{
		if (terrains.Count < 2)
		{
			return;
		}
		float[,,] array = null;
		int num = default(int);
		int num2 = default(int);
		for (int i = 0; i < terrains.Count; i++)
		{
			num = search_terrain_top(terrains[i]);
			if (num != -1)
			{
				num2 = terrains[num].terrain.terrainData.alphamapResolution;
				if (terrains[i].terrain.terrainData.alphamapResolution != num2 || terrains[i].terrain.terrainData.splatPrototypes.Length != terrains[num].terrain.terrainData.splatPrototypes.Length)
				{
					continue;
				}
				array = terrains[num].terrain.terrainData.GetAlphamaps(0, 0, num2, 1);
				terrains[i].terrain.terrainData.SetAlphamaps(0, num2 - 1, array);
			}
			num = search_terrain_left(terrains[i]);
			if (num != -1)
			{
				num2 = terrains[num].terrain.terrainData.alphamapResolution;
				if (terrains[i].terrain.terrainData.alphamapResolution == num2 && terrains[i].terrain.terrainData.splatPrototypes.Length == terrains[num].terrain.terrainData.splatPrototypes.Length)
				{
					array = terrains[num].terrain.terrainData.GetAlphamaps(num2 - 1, 0, 1, num2);
					terrains[i].terrain.terrainData.SetAlphamaps(0, 0, array);
				}
			}
		}
	}

	public int search_terrain_top(terrain_class preterrain1)
	{
		int result;
		if (preterrain1.terrain == null)
		{
			result = -1;
		}
		else if (preterrain1.terrain.terrainData == null)
		{
			result = -1;
		}
		else
		{
			int num = 0;
			while (true)
			{
				if (num < terrains.Count)
				{
					if (!(terrains[num].terrain == null) && !(terrains[num].terrain.terrainData == null))
					{
						Vector3 vector = terrains[num].terrain.transform.position;
						float x = vector.x;
						Vector3 vector2 = preterrain1.terrain.transform.position;
						if (x == vector2.x)
						{
							Vector3 vector3 = terrains[num].terrain.transform.position;
							float z = vector3.z;
							Vector3 vector4 = preterrain1.terrain.transform.position;
							float z2 = vector4.z;
							Vector3 size = preterrain1.terrain.terrainData.size;
							if (z == z2 + size.z)
							{
								result = num;
								break;
							}
						}
					}
					num++;
					continue;
				}
				result = -1;
				break;
			}
		}
		return result;
	}

	public int search_terrain_left(terrain_class preterrain1)
	{
		int result;
		if (preterrain1.terrain == null)
		{
			result = -1;
		}
		else if (preterrain1.terrain.terrainData == null)
		{
			result = -1;
		}
		else
		{
			int num = 0;
			while (true)
			{
				if (num < terrains.Count)
				{
					if (!(terrains[num].terrain == null) && !(terrains[num].terrain.terrainData == null))
					{
						Vector3 vector = terrains[num].terrain.transform.position;
						float z = vector.z;
						Vector3 vector2 = preterrain1.terrain.transform.position;
						if (z == vector2.z)
						{
							Vector3 vector3 = terrains[num].terrain.transform.position;
							float x = vector3.x;
							Vector3 vector4 = preterrain1.terrain.transform.position;
							float x2 = vector4.x;
							Vector3 size = preterrain1.terrain.terrainData.size;
							if (x == x2 - size.x)
							{
								result = num;
								break;
							}
						}
					}
					num++;
					continue;
				}
				result = -1;
				break;
			}
		}
		return result;
	}

	public void smooth_terrain(terrain_class preterrain1, float strength)
	{
		if (!preterrain1.terrain)
		{
			return;
		}
		int heightmapResolution = preterrain1.terrain.terrainData.heightmapResolution;
		float num = default(float);
		float num2 = default(float);
		float num3 = 1f;
		float num4 = 1f;
		float num5 = 0f;
		int num6 = 0;
		float num7 = default(float);
		float num8 = default(float);
		float num9 = default(float);
		heights = preterrain1.terrain.terrainData.GetHeights(0, 0, heightmapResolution, heightmapResolution);
		for (int i = 0; i < smooth_tool_repeat; i++)
		{
			for (int j = 0; j < heightmapResolution; j++)
			{
				for (int k = 1; k < heightmapResolution - 1; k++)
				{
					num2 = heights[k - 1, j];
					num7 = heights[k, j];
					num8 = heights[k + 1, j];
					num = num7 - (num2 + num8) / 2f;
					if (smooth_tool_advanced)
					{
						num3 = smooth_tool_height_curve.curve.Evaluate(num7);
						num4 = smooth_tool_angle_curve.curve.Evaluate(calc_terrain_angle(preterrain1, k, j, settings.smooth_angle) / 90f);
					}
					num *= 1f - strength * num3 * num4;
					num9 = num + (num2 + num8) / 2f;
					heights[k, j] = num9;
				}
			}
			for (int j = 1; j < heightmapResolution - 1; j++)
			{
				for (int k = 0; k < heightmapResolution; k++)
				{
					num2 = heights[k, j - 1];
					num7 = heights[k, j];
					num8 = heights[k, j + 1];
					num = num7 - (num2 + num8) / 2f;
					if (smooth_tool_advanced)
					{
						num3 = smooth_tool_height_curve.curve.Evaluate(num7);
						num4 = smooth_tool_angle_curve.curve.Evaluate(calc_terrain_angle(preterrain1, k, j, settings.smooth_angle) / 90f);
					}
					num *= 1f - strength * num3 * num4;
					num9 = num + (num2 + num8) / 2f;
					heights[k, j] = num9;
				}
			}
		}
		preterrain1.terrain.terrainData.SetHeights(0, 0, heights);
		if (!(preterrain1.color_terrain[0] >= 1.5f))
		{
			preterrain1.color_terrain += new Color(0.5f, 0.5f, 1f, 0.5f);
		}
	}

	public void get_terrains_minmax()
	{
		float num = default(float);
		float num2 = default(float);
		float num3 = default(float);
		Vector3 vector = default(Vector3);
		settings.terrainMinHeight = 1E+08f;
		settings.terrainMaxHeight = 0f;
		settings.terrainMinDegree = 100f;
		settings.terrainMaxDegree = 0f;
		for (int i = 0; i < terrains.Count; i++)
		{
			if (!terrains[i].terrain || !terrains[i].terrain.terrainData)
			{
				continue;
			}
			num = terrains[i].terrain.terrainData.heightmapResolution;
			vector = terrains[i].terrain.terrainData.size;
			for (int j = 0; (float)j < num; j++)
			{
				for (int k = 0; (float)k < num; k++)
				{
					num2 = terrains[i].terrain.terrainData.GetHeight(k, j);
					if (!(num2 >= settings.terrainMinHeight))
					{
						settings.terrainMinHeight = num2;
					}
					if (!(num2 <= settings.terrainMaxHeight))
					{
						settings.terrainMaxHeight = num2;
					}
					num3 = calc_terrain_angle(terrains[i], (float)k / num * vector.x, (float)j / num * vector.z, settings.smooth_angle);
					if (!(num3 >= settings.terrainMinDegree))
					{
						settings.terrainMinDegree = num3;
					}
					if (!(num3 <= settings.terrainMaxDegree))
					{
						settings.terrainMaxDegree = num3;
					}
				}
			}
		}
	}

	public void get_meshes_minmax_height()
	{
		settings.terrainMinHeight = 1E+08f;
		settings.terrainMaxHeight = 0f;
		settings.terrainMinDegree = 0f;
		settings.terrainMaxDegree = 0f;
		for (int i = 0; i < meshes.Count; i++)
		{
			if ((bool)meshes[i].mesh)
			{
				Vector3 min = meshes[i].mesh.bounds.min;
				if (!(min.y >= settings.terrainMinHeight))
				{
					settings_class settings_class = settings;
					Vector3 min2 = meshes[i].mesh.bounds.min;
					settings_class.terrainMinHeight = min2.y;
				}
				Vector3 max = meshes[i].mesh.bounds.max;
				if (!(max.y <= settings.terrainMaxHeight))
				{
					settings_class settings_class2 = settings;
					Vector3 max2 = meshes[i].mesh.bounds.max;
					settings_class2.terrainMaxHeight = max2.y;
				}
			}
		}
		meshes_heightscale = settings.terrainMaxHeight;
	}

	public void smooth_all_terrain(float strength)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			if (terrains[i].active)
			{
				smooth_terrain(terrains[i], strength);
			}
		}
	}

	public void set_smooth_tool_terrain_popup()
	{
		if (terrains.Count > 1)
		{
			smooth_tool_terrain = new string[terrains.Count + 1];
			smooth_tool_terrain[terrains.Count] = "All";
			smooth_tool_terrain_select = terrains.Count;
		}
		else
		{
			smooth_tool_terrain = new string[1];
			smooth_tool_terrain_select = 0;
		}
		for (int i = 0; i < terrains.Count; i++)
		{
			smooth_tool_terrain[i] = terrains[i].name;
		}
	}

	public void convert_software_version()
	{
		if (!(converted_version >= 1.04f))
		{
			int num = 0;
			for (int i = 0; i < prelayers.Count; i++)
			{
				for (int j = 0; j < prelayers[i].layer.Count; j++)
				{
					for (int k = 0; k < prelayers[i].layer[j].color_output.precolor_range.Count; k++)
					{
						convert_precolor_range(prelayers[i].layer[j].color_output.precolor_range[k]);
					}
				}
			}
			for (int l = 0; l < filter.Count; l++)
			{
				convert_precolor_range(filter[l].preimage.precolor_range);
			}
			for (int m = 0; m < subfilter.Count; m++)
			{
				convert_precolor_range(subfilter[m].preimage.precolor_range);
			}
			converted_version = 1.04f;
		}
		if (converted_version >= 1.8f)
		{
			return;
		}
		for (int n = 0; n < prelayers.Count; n++)
		{
			for (int num2 = 0; num2 < prelayers[n].layer.Count; num2++)
			{
				prelayers[n].layer[num2].splat_output.splat_value.SyncValueMulti();
				prelayers[n].layer[num2].grass_output.grass_value.SyncValueMulti();
				prelayers[n].layer[num2].tree_output.tree_value.SyncValueMulti();
				prelayers[n].layer[num2].object_output.object_value.SyncValueMulti();
			}
		}
		SyncSplatCustom();
		converted_version = 1.8f;
	}

	public void SyncSplatCustom()
	{
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				prelayers[i].layer[j].splat_output.SyncSplatCustom(terrains[0].splatPrototypes.Count);
			}
		}
	}

	public void convert_precolor_range(precolor_range_class precolor_range)
	{
		precolor_range.color_range_value.calc_value();
	}

	public void filter_texture(int previewMode)
	{
		if (!texture_tool.preimage.image[0])
		{
			return;
		}
		int width = texture_tool.preimage.image[0].width;
		int num = texture_tool.preimage.image[0].height;
		if (texture_tool.preimage.image.Count == 1)
		{
			texture_tool.preimage.image.Add(new Texture2D(1, 1));
		}
		if (!texture_tool.preimage.image[1])
		{
			texture_tool.preimage.image[1] = new Texture2D(1, 1);
		}
		if ((float)texture_tool.preimage.image[1].width != texture_tool.resolution_display.x || (float)texture_tool.preimage.image[1].height != texture_tool.resolution_display.x)
		{
			texture_tool.preimage.image[1].Resize((int)texture_tool.resolution_display.x, (int)texture_tool.resolution_display.y);
		}
		int width2 = texture_tool.preimage.image[1].width;
		int num2 = texture_tool.preimage.image[1].height;
		Vector2 vector = new Vector2(width / width2, num / num2);
		int count = texture_tool.precolor_range.color_range.Count;
		bool flag = false;
		Color color = default(Color);
		Color color2 = default(Color);
		Color color3 = default(Color);
		for (int i = 0; i < num2; i++)
		{
			for (int j = 0; j < width2; j++)
			{
				flag = false;
				color3 = texture_tool.preimage.image[0].GetPixel((int)((float)j * vector.x), (int)((float)i * vector.y));
				for (int k = 0; k < count; k++)
				{
					if (!texture_tool.precolor_range.color_range_value.active[k])
					{
						continue;
					}
					color = texture_tool.precolor_range.color_range[k].color_start;
					color2 = texture_tool.precolor_range.color_range[k].color_end;
					if (texture_tool.precolor_range.color_range[k].one_color)
					{
						if (color3 == color)
						{
							flag = true;
							if ((previewMode & 1) != 0)
							{
								color3 = choose_color(k, 1f);
							}
						}
					}
					else if (color_in_range(color3, color, color2))
					{
						if (!texture_tool.precolor_range.color_range[k].invert)
						{
							if ((previewMode & 1) != 0)
							{
								color3 = choose_color(k, texture_tool.precolor_range.color_range[k].curve.Evaluate(calc_color_pos(color3, color, color2)));
							}
							flag = true;
						}
					}
					else if (texture_tool.precolor_range.color_range[k].invert)
					{
						flag = true;
						if ((previewMode & 1) != 0)
						{
							color3 = choose_color(k, 1f - texture_tool.precolor_range.color_range[k].curve.Evaluate(calc_color_pos(color3, color, color2)));
						}
					}
				}
				if (!flag && (previewMode & 2) == 0)
				{
					color3 = new Color(0f, 0f, 0f);
				}
				texture_tool.preimage.image[1].SetPixel(j, i, color3);
			}
		}
		texture_tool.preimage.image[1].Apply();
	}

	public Color choose_color(int index, float falloff)
	{
		Color result = Color.red;
		switch (index)
		{
		case 0:
			result = Color.red * falloff;
			break;
		case 1:
			result = Color.green * falloff;
			break;
		case 2:
			result = Color.blue * falloff;
			break;
		case 3:
			result = Color.yellow * falloff;
			break;
		case 4:
			result = Color.white * falloff;
			break;
		case 5:
			result = Color.cyan * falloff;
			break;
		case 6:
			result = Color.magenta * falloff;
			break;
		case 7:
			result = Color.grey * falloff;
			break;
		}
		return result;
	}

	public AnimationCurve set_curve_linear(AnimationCurve curve)
	{
		AnimationCurve animationCurve = new AnimationCurve();
		for (int i = 0; i < curve.keys.Length; i++)
		{
			float inTangent = 0f;
			float outTangent = 0f;
			bool flag = false;
			bool flag2 = false;
			Vector2 vector = default(Vector2);
			Vector2 vector2 = default(Vector2);
			Vector2 vector3 = default(Vector2);
			Keyframe key = curve[i];
			if (i == 0)
			{
				inTangent = 0f;
				flag = true;
			}
			if (i == curve.keys.Length - 1)
			{
				outTangent = 0f;
				flag2 = true;
			}
			if (!flag)
			{
				vector.x = curve.keys[i - 1].time;
				vector.y = curve.keys[i - 1].value;
				vector2.x = curve.keys[i].time;
				vector2.y = curve.keys[i].value;
				vector3 = vector2 - vector;
				inTangent = vector3.y / vector3.x;
			}
			if (!flag2)
			{
				vector.x = curve.keys[i].time;
				vector.y = curve.keys[i].value;
				vector2.x = curve.keys[i + 1].time;
				vector2.y = curve.keys[i + 1].value;
				vector3 = vector2 - vector;
				outTangent = vector3.y / vector3.x;
			}
			key.inTangent = inTangent;
			key.outTangent = outTangent;
			animationCurve.AddKey(key);
		}
		return animationCurve;
	}

	public float perlin_noise(float x, float y, float offset_x, float offset_y, float frequency, float octaves, float detail_strength)
	{
		frequency *= current_layer.zoom;
		offset_x += current_layer.offset.x;
		offset_y += current_layer.offset.y;
		float num = Mathf.PerlinNoise((x + frequency * (offset_x + 50f)) / frequency, (y + frequency * (offset_y + 50f)) / frequency);
		float num2 = 2f;
		for (float num3 = 1f; num3 < octaves; num3 += 1f)
		{
			num += (Mathf.PerlinNoise((x + frequency * (offset_x + 50f)) / (frequency / num2), (y + frequency * (offset_y + 50f)) / (frequency / num2)) - 0.5f) / num2;
			num2 *= detail_strength;
		}
		return num;
	}

	public float clamp_range(float number, float start, float end)
	{
		return (end - start) * number + start;
	}

	public void create_perlin(int preview_resolution, int resolution, export_mode_enum mode, bool save)
	{
		float num = (float)resolution * 1f / ((float)preview_resolution * 1f);
		int num2 = default(int);
		float num3 = default(float);
		float num4 = default(float);
		float num5 = default(float);
		int num6 = preview_resolution * preview_resolution;
		int num7 = default(int);
		float frequency = heightmap_tool.perlin.frequency;
		switch (mode)
		{
		case export_mode_enum.Image:
		{
			Color[] array = default(Color[]);
			if (mode == export_mode_enum.Image)
			{
				array = new Color[num6];
			}
			Color color = default(Color);
			for (num3 = 0f; num3 < (float)resolution; num3 += num)
			{
				for (num4 = 0f; num4 < (float)resolution; num4 += num)
				{
					color[0] = Mathf.PerlinNoise(((float)(-(resolution / 2)) + num4 + frequency * (heightmap_tool.perlin.offset.x + 5000f)) / frequency, ((float)(-(resolution / 2)) + num3 + frequency * (heightmap_tool.perlin.offset.y + 5000f)) / frequency);
					num5 = 2f;
					for (num2 = 1; num2 < heightmap_tool.perlin.octaves; num2++)
					{
						color[0] += (Mathf.PerlinNoise(((float)(-(resolution / 2)) + num4 + frequency * (heightmap_tool.perlin.offset.x + 5000f)) / (frequency / num5), ((float)(-(resolution / 2)) + num3 + frequency * (heightmap_tool.perlin.offset.y + 5000f)) / (frequency / num5)) - 0.5f) / num5;
						num5 *= 2f;
					}
					color[0] = color[0];
					color[1] = color[0];
					color[2] = color[0];
					num7 = (int)(num4 / num + num3 / num * (float)preview_resolution);
					if (num7 > num6 - 1)
					{
						num7 = num6 - 1;
					}
					array[num7] = color;
				}
			}
			if (save)
			{
				if (preview_resolution != heightmap_tool.output_texture.width)
				{
					heightmap_tool.output_texture.Resize(resolution, resolution);
				}
				heightmap_tool.output_texture.SetPixels(array);
				heightmap_tool.output_texture.Apply();
			}
			else
			{
				heightmap_tool.preview_texture.SetPixels(array);
				heightmap_tool.preview_texture.Apply();
			}
			break;
		}
		case export_mode_enum.Raw:
		{
			if (!save)
			{
				break;
			}
			heightmap_tool.raw_save_file.bytes = new byte[resolution * resolution * 2];
			int num8 = 0;
			int num9 = 0;
			int num10 = default(int);
			int num11 = default(int);
			int num12 = 0;
			ushort num13 = default(ushort);
			float num14 = default(float);
			if (heightmap_tool.raw_save_file.mode == raw_mode_enum.Mac)
			{
				for (num4 = 0f; num4 < (float)resolution; num4 += 1f)
				{
					for (num3 = 0f; num3 < (float)resolution; num3 += 1f)
					{
						num14 = Mathf.PerlinNoise((num4 + heightmap_tool.perlin.offset.x + 1000000f) / heightmap_tool.perlin.frequency, (num3 + heightmap_tool.perlin.offset.y + 1000000f) / heightmap_tool.perlin.frequency);
						num5 = 2f;
						for (num2 = 1; num2 < heightmap_tool.perlin.octaves; num2++)
						{
							num14 += (Mathf.PerlinNoise((num4 + heightmap_tool.perlin.offset.x + 1000000f) / (heightmap_tool.perlin.frequency / num5), (num3 + heightmap_tool.perlin.offset.y + 1000000f) / (heightmap_tool.perlin.frequency / num5)) - 0.5f) / num5;
							num5 *= 2f;
						}
						num14 = heightmap_tool.perlin.precurve.curve.Evaluate(num14) * 65535f;
						if (!(num14 >= 0f))
						{
							num14 = 0f;
						}
						if (!(num14 <= 65535f))
						{
							num14 = 65535f;
						}
						num13 = (ushort)num14;
						num10 = (int)((uint)num13 >> 8);
						num11 = num13 - (num10 << 8);
						byte[] bytes = heightmap_tool.raw_save_file.bytes;
						int num15;
						num12 = (num15 = num12) + 1;
						bytes[num15] = (byte)num10;
						byte[] bytes2 = heightmap_tool.raw_save_file.bytes;
						int num16;
						num12 = (num16 = num12) + 1;
						bytes2[num16] = (byte)num11;
					}
				}
			}
			else
			{
				if (heightmap_tool.raw_save_file.mode != 0)
				{
					break;
				}
				for (num4 = 0f; num4 < (float)resolution; num4 += 1f)
				{
					for (num3 = 0f; num3 < (float)resolution; num3 += 1f)
					{
						num14 = Mathf.PerlinNoise((num4 + heightmap_tool.perlin.offset.x + 1000000f) / heightmap_tool.perlin.frequency, (num3 + heightmap_tool.perlin.offset.y + 1000000f) / heightmap_tool.perlin.frequency);
						num5 = 2f;
						for (num2 = 1; num2 < heightmap_tool.perlin.octaves; num2++)
						{
							num14 += (Mathf.PerlinNoise((num4 + heightmap_tool.perlin.offset.x + 1000000f) / (heightmap_tool.perlin.frequency / num5), (num3 + heightmap_tool.perlin.offset.y + 1000000f) / (heightmap_tool.perlin.frequency / num5)) - 0.5f) / num5;
							num5 *= 2f;
						}
						num14 = heightmap_tool.perlin.precurve.curve.Evaluate(num14) * 65535f;
						if (!(num14 >= 0f))
						{
							num14 = 0f;
						}
						if (!(num14 <= 65535f))
						{
							num14 = 65535f;
						}
						num13 = (ushort)num14;
						num10 = (int)((uint)num13 >> 8);
						num11 = num13 - (num10 << 8);
						byte[] bytes3 = heightmap_tool.raw_save_file.bytes;
						int num17;
						num12 = (num17 = num12) + 1;
						bytes3[num17] = (byte)num11;
						byte[] bytes4 = heightmap_tool.raw_save_file.bytes;
						int num18;
						num12 = (num18 = num12) + 1;
						bytes4[num18] = (byte)num10;
					}
				}
			}
			break;
		}
		}
	}

	public bool generate_pattern_start()
	{
		if (pattern_tool.clear)
		{
			for (int i = 0; i < pattern_tool.output_texture.height; i++)
			{
				for (int j = 0; j < pattern_tool.output_texture.width; j++)
				{
					pattern_tool.output_texture.SetPixel(j, i, new Color(0f, 0f, 0f));
				}
			}
		}
		pattern_tool.place_total = 0;
		int num = 0;
		int result;
		while (true)
		{
			if (num < pattern_tool.patterns.Count)
			{
				if (!pattern_tool.patterns[num].input_texture)
				{
					result = 0;
					break;
				}
				pattern_tool.patterns[num].pattern_placed.Clear();
				pattern_tool.patterns[num].placed_max = false;
				pattern_tool.place_total += pattern_tool.patterns[num].place_max;
				pattern_tool.patterns[num].width = pattern_tool.patterns[num].input_texture.width / pattern_tool.patterns[num].count_x;
				pattern_tool.patterns[num].height = pattern_tool.patterns[num].input_texture.height / pattern_tool.patterns[num].count_y;
				num++;
				continue;
			}
			result = 1;
			break;
		}
		return (byte)result != 0;
	}

	public bool generate_pattern()
	{
		bool result = true;
		pick_pattern();
		draw_pattern();
		for (int i = 0; i < pattern_tool.patterns.Count; i++)
		{
			if (!pattern_tool.patterns[i].placed_max && pattern_tool.patterns[i].active)
			{
				result = false;
			}
		}
		return result;
	}

	public void pick_pattern()
	{
		int num = default(int);
		do
		{
			num = UnityEngine.Random.Range(0, pattern_tool.patterns.Count);
		}
		while (pattern_tool.patterns[num].placed_max || !pattern_tool.patterns[num].active);
		pattern_tool.current_pattern = pattern_tool.patterns[num];
		pattern_tool.current_pattern.current_x = UnityEngine.Random.Range(0, pattern_tool.current_pattern.count_x);
		pattern_tool.current_pattern.current_y = UnityEngine.Random.Range(0, pattern_tool.current_pattern.count_y);
		pattern_tool.current_pattern.rotation = UnityEngine.Random.Range(pattern_tool.current_pattern.rotation_start, pattern_tool.current_pattern.rotation_end);
		pattern_tool.current_pattern.width2 = pattern_tool.current_pattern.width / 2f;
		pattern_tool.current_pattern.height2 = pattern_tool.current_pattern.height / 2f;
		pattern_tool.current_pattern.start_x = pattern_tool.current_pattern.current_x * pattern_tool.current_pattern.width;
		pattern_tool.current_pattern.start_y = pattern_tool.current_pattern.current_y * pattern_tool.current_pattern.height;
		pattern_tool.current_pattern.scale.x = 1f / UnityEngine.Random.Range(pattern_tool.current_pattern.scale_start.x, pattern_tool.current_pattern.scale_end.x);
		float num2 = pattern_tool.current_pattern.scale_end.x - pattern_tool.current_pattern.scale_start.x;
		float num3 = pattern_tool.current_pattern.scale.x - pattern_tool.current_pattern.scale_start.x;
		float num4 = num3 / num2 * 100f;
		pattern_tool.current_pattern.scale.y = pattern_tool.current_pattern.scale.x;
		float num5 = pattern_tool.current_pattern.scale_end.y - pattern_tool.current_pattern.scale_start.y;
		float num6 = pattern_tool.current_pattern.scale.y - pattern_tool.current_pattern.scale_start.y;
		float num7 = num6 / num5 * 100f;
		float num8 = Mathf.Abs(num4 - num7);
	}

	public void draw_pattern()
	{
		if (pattern_tool.current_pattern.pattern_placed.Count >= pattern_tool.current_pattern.place_max)
		{
			pattern_tool.current_pattern.placed_max = true;
			return;
		}
		Vector2 item = default(Vector2);
		Color color = default(Color);
		Color color2 = default(Color);
		Vector2 vector = default(Vector2);
		Vector2 vector2 = default(Vector2);
		bool flag = false;
		item.x = UnityEngine.Random.Range(0f - pattern_tool.current_pattern.width, pattern_tool.output_texture.width);
		item.y = UnityEngine.Random.Range(0f - pattern_tool.current_pattern.height, pattern_tool.output_texture.height);
		float rotation = pattern_tool.current_pattern.rotation;
		for (float num = 0f; num < pattern_tool.current_pattern.height + pattern_tool.current_pattern.height2; num += pattern_tool.current_pattern.scale.y)
		{
			for (float num2 = 0f; num2 < pattern_tool.current_pattern.width + pattern_tool.current_pattern.width2; num2 += pattern_tool.current_pattern.scale.x)
			{
				vector2.x = num2 / pattern_tool.current_pattern.scale.x + item.x;
				vector2.y = num / pattern_tool.current_pattern.scale.y + item.y;
				if (vector2.x >= pattern_tool.output_resolution.x || vector2.y >= pattern_tool.output_resolution.y || vector2.x < 0f || !(vector2.y >= 0f))
				{
					continue;
				}
				vector.x = num2 + pattern_tool.current_pattern.start_x - pattern_tool.current_pattern.width2 / 2f;
				vector.y = num + pattern_tool.current_pattern.start_y - pattern_tool.current_pattern.height2 / 2f;
				vector = calc_rotation_pixel(vector.x, vector.y, pattern_tool.current_pattern.start_x + pattern_tool.current_pattern.width / 2f, pattern_tool.current_pattern.start_y + pattern_tool.current_pattern.height / 2f, pattern_tool.current_pattern.rotation);
				if (vector.x - pattern_tool.current_pattern.start_x < 0f || !(vector.x - pattern_tool.current_pattern.start_x <= pattern_tool.current_pattern.width) || vector.y - pattern_tool.current_pattern.start_y < 0f || !(vector.y - pattern_tool.current_pattern.start_y <= pattern_tool.current_pattern.height))
				{
					continue;
				}
				color = pattern_tool.current_pattern.input_texture.GetPixel((int)vector.x, (int)vector.y) * pattern_tool.current_pattern.color;
				color[0] *= pattern_tool.current_pattern.strength;
				color[1] *= pattern_tool.current_pattern.strength;
				color[2] *= pattern_tool.current_pattern.strength;
				color2 = pattern_tool.output_texture.GetPixel((int)vector2.x, (int)vector2.y);
				flag = false;
				for (int i = 0; i < pattern_tool.current_pattern.precolor_range.color_range.Count; i++)
				{
					if (color_in_range(color, pattern_tool.current_pattern.precolor_range.color_range[i].color_start, pattern_tool.current_pattern.precolor_range.color_range[i].color_end))
					{
						if (!pattern_tool.current_pattern.precolor_range.color_range[i].invert)
						{
							flag = true;
						}
					}
					else if (pattern_tool.current_pattern.precolor_range.color_range[i].invert)
					{
						flag = true;
					}
				}
				condition_output_enum output = pattern_tool.current_pattern.output;
				switch (output)
				{
				case condition_output_enum.add:
					color += color2;
					break;
				case condition_output_enum.subtract:
					color = color2 - color;
					break;
				case condition_output_enum.multiply:
					color = color2 * color;
					break;
				case condition_output_enum.divide:
					color[0] = color2[0] / color[0];
					color[1] = color2[1] / color[1];
					color[2] = color2[2] / color[2];
					break;
				case condition_output_enum.difference:
					color[0] = Mathf.Abs(color2[0] - color[0]);
					color[1] = Mathf.Abs(color2[1] - color[1]);
					color[2] = Mathf.Abs(color2[2] - color[2]);
					break;
				case condition_output_enum.average:
					color = (color + color2) / 2f;
					break;
				case condition_output_enum.max:
					if (!(color[0] >= color2[0]) && !(color[1] >= color2[1]) && !(color[2] >= color2[2]))
					{
						flag = false;
					}
					break;
				default:
					if (output == condition_output_enum.max && !(color[0] <= color2[0]) && !(color[1] <= color2[1]) && !(color[2] <= color2[2]))
					{
						flag = false;
					}
					break;
				case condition_output_enum.change:
					break;
				}
				if (flag)
				{
					pattern_tool.output_texture.SetPixel((int)vector2.x, (int)vector2.y, color);
				}
			}
		}
		pattern_tool.current_pattern.pattern_placed.Add(item);
	}

	public float calc_floor(float number)
	{
		int num = (int)number;
		return num;
	}

	public void normalize_splat(terrain_class preterrain1)
	{
		int length = preterrain1.terrain.terrainData.splatPrototypes.Length;
		preterrain1.map = preterrain1.terrain.terrainData.GetAlphamaps(0, 0, preterrain1.terrain.terrainData.alphamapResolution, preterrain1.terrain.terrainData.alphamapResolution);
		float num = default(float);
		for (int i = 0; (float)i < preterrain.splatmap_resolution; i++)
		{
			for (int j = 0; (float)j < preterrain.splatmap_resolution; j++)
			{
				num = 0f;
				for (int k = 0; k < length; k++)
				{
					num += preterrain1.map[j, i, k];
				}
				for (int k = 0; k < length; k++)
				{
					preterrain1.map[j, i, k] = preterrain1.map[j, i, k] / num;
				}
			}
		}
		preterrain1.terrain.terrainData.SetAlphamaps(0, 0, preterrain1.map);
	}

	public float calc_terrain_angle(terrain_class preterrain1, float x, float y, int smooth)
	{
		Vector3 size = preterrain1.terrain.terrainData.size;
		float num = preterrain1.terrain.terrainData.heightmapResolution;
		float num2 = size.x / (num - 1f);
		short num3 = (short)(x / num2);
		short num4 = (short)(y / num2);
		bool flag = false;
		short num5 = (short)(num3 - smooth);
		short num6 = (short)(num4 + smooth);
		terrain_class terrain_class = preterrain1;
		short num7 = (short)(num3 + smooth);
		short num8 = (short)(num4 + smooth);
		terrain_class terrain_class2 = preterrain1;
		short num9 = (short)(num3 - smooth);
		short num10 = (short)(num4 - smooth);
		terrain_class terrain_class3 = preterrain1;
		short num11 = (short)(num3 + smooth);
		short num12 = (short)(num4 - smooth);
		terrain_class terrain_class4 = preterrain1;
		if (num5 < 0)
		{
			if (!RuntimeServices.EqualityOperator(preterrain1.neighbors[3], null))
			{
				terrain_class = preterrain1.neighbors[3];
				num5 = (short)(num - 1f + (float)num5);
				num9 = num5;
				flag = true;
			}
			else
			{
				num7 = (short)(num7 - num5);
				num11 = num7;
				num5 = 0;
				num9 = num5;
			}
		}
		else if (!((float)num7 <= num - 1f))
		{
			if (!RuntimeServices.EqualityOperator(preterrain1.neighbors[1], null))
			{
				terrain_class2 = preterrain1.neighbors[1];
				num7 = (short)((float)num7 - (num - 1f));
				num11 = num7;
				flag = true;
			}
			else
			{
				num5 = (short)((float)num5 - ((float)num7 - (num - 1f)));
				num9 = num5;
				num7 = (short)(num - 1f);
				num11 = num7;
			}
		}
		if (num10 < 0)
		{
			if (!RuntimeServices.EqualityOperator(terrain_class.neighbors[0], null))
			{
				terrain_class3 = terrain_class.neighbors[0];
				num10 = (short)(num - 1f + (float)num10);
				num12 = num10;
				flag = true;
			}
			else
			{
				num6 = (short)(num6 - num10);
				num8 = num6;
				num10 = 0;
				num12 = num10;
			}
		}
		else if (!((float)num6 <= num - 1f))
		{
			if (!RuntimeServices.EqualityOperator(terrain_class2.neighbors[2], null))
			{
				terrain_class4 = terrain_class2.neighbors[2];
				num6 = (short)((float)num6 - (num - 1f));
				num8 = num6;
				flag = true;
			}
			else
			{
				num10 = (short)((float)num10 - ((float)num6 - (num - 1f)));
				num12 = num10;
				num6 = (short)(num - 1f);
				num8 = num6;
			}
		}
		float num13 = default(float);
		float num14 = default(float);
		float num15 = default(float);
		float num16 = default(float);
		if (flag)
		{
			num13 = terrain_class.terrain.terrainData.GetHeight(num5, num6);
			num14 = terrain_class2.terrain.terrainData.GetHeight(num7, num8);
			num15 = terrain_class3.terrain.terrainData.GetHeight(num9, num10);
			num16 = terrain_class4.terrain.terrainData.GetHeight(num11, num12);
		}
		else
		{
			num13 = preterrain1.terrain.terrainData.GetHeight(num5, num6);
			num14 = preterrain1.terrain.terrainData.GetHeight(num7, num8);
			num15 = preterrain1.terrain.terrainData.GetHeight(num9, num10);
			num16 = preterrain1.terrain.terrainData.GetHeight(num11, num12);
		}
		float num17 = default(float);
		float num18 = default(float);
		if (!(num13 <= num14))
		{
			num18 = num13;
			num17 = num14;
		}
		else
		{
			num18 = num14;
			num17 = num13;
		}
		if (!(num15 <= num18))
		{
			num18 = num15;
		}
		if (!(num16 <= num18))
		{
			num18 = num16;
		}
		if (!(num15 >= num17))
		{
			num17 = num15;
		}
		if (!(num16 >= num17))
		{
			num17 = num16;
		}
		float num19 = Mathf.Round((num18 - num17) * (float)(101 - settings.round_angle)) / (float)(101 - settings.round_angle);
		float num20 = size.x / num * ((float)smooth * 2f + 1f);
		return Mathf.Atan(num19 / num20) * Rad2Deg;
	}

	public int find_terrain_by_position(Vector3 position)
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < terrains.Count)
			{
				if (terrains[num].rect.Contains(new Vector2(position.x, position.z)))
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public int find_terrain(int tile_x, int tile_y)
	{
		int num = 0;
		int result;
		while (true)
		{
			if (num < terrains.Count)
			{
				if (terrains[num].tile_x == (float)tile_x && terrains[num].tile_z == (float)tile_y)
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			if (!generate_error)
			{
				UnityEngine.Debug.Log("The order of the terrains has been changed! If you have more terrains please shift click <Fit All> in Terrain List -> Data -> Size.");
				generate_error = true;
				reset_terrains_tiles(script_base);
			}
			result = 0;
			break;
		}
		return result;
	}

	public void calc_terrain_needed_tiles()
	{
		terrainInstances = new Vector2(terrainTiles.x - terrains[0].tiles.x, terrainTiles.y - terrains[0].tiles.y);
		terrain_instances = (int)(terrainTiles.x * terrainTiles.y - (float)terrains.Count);
	}

	public void calc_terrain_one_more_tile()
	{
		terrain_tiles = (int)(terrains[0].tiles.x + 1f);
		calc_terrain_needed_tiles();
	}

	public tile_class calc_terrain_tile(int terrain_index, tile_class tiles)
	{
		tile_class tile_class = new tile_class();
		tile_class.y = terrain_index / tiles.x;
		tile_class.x = terrain_index - tile_class.y * tiles.x;
		return tile_class;
	}

	public int calc_terrain_index2(tile_class tile, tile_class tiles)
	{
		return tile.x + tile.y * tiles.x;
	}

	public int find_terrain_by_name(Terrain terrain)
	{
		string name = terrain.name;
		int num = 0;
		int result;
		while (true)
		{
			if (num < terrains.Count)
			{
				if ((bool)terrains[num].terrain && terrains[num].terrain.name == name)
				{
					result = num;
					break;
				}
				num++;
				continue;
			}
			result = -1;
			break;
		}
		return result;
	}

	public void reset_terrains_tiles(terraincomposer_save script_save)
	{
		for (int i = 0; i < terrains.Count; i++)
		{
			script_save.terrains[i].tiles = new Vector2(1f, 1f);
			script_save.terrains[i].tile_x = 0f;
			script_save.terrains[i].tile_z = 0f;
		}
	}

	public string sec_to_timeMin(float seconds, bool display_seconds)
	{
		int num = (int)(seconds / 60f);
		seconds -= (float)(num * 60);
		object result;
		if (num == 0)
		{
			result = seconds.ToString("F2");
		}
		else
		{
			int num2 = (int)seconds;
			seconds -= (float)num2;
			int num3 = (int)(seconds * 100f);
			result = ((!display_seconds) ? (num.ToString() + ":" + num2.ToString("D2")) : (num.ToString() + ":" + num2.ToString("D2") + "." + num3.ToString("D2")));
		}
		return (string)result;
	}

	public void get_rtp_lodmanager()
	{
		RTP_LODmanager1 = GameObject.Find("_RTP_LODmanager");
		if ((bool)RTP_LODmanager1)
		{
			rtpLod_script = RTP_LODmanager1.GetComponent("RTP_LODmanager");
		}
	}

	public int generate_object(prelayer_class prelayer3)
	{
		frames = 1f / (Time.realtimeSinceStartup - auto_speed_time);
		auto_speed_time = Time.realtimeSinceStartup;
		break_x = false;
		row_object_count = 0;
		prelayer3.counter_y = prelayer3.y;
		int result;
		while (true)
		{
			object_class object_class;
			Quaternion lhs;
			if (prelayer3.counter_y >= prelayer3.y - (float)generate_speed * prelayer.prearea.step.y)
			{
				generate_call_time = Time.realtimeSinceStartup;
				float y = prelayer3.y;
				int num = default(int);
				if (!(prelayer3.counter_y >= prelayer3.prearea.area.yMin))
				{
					if (prelayer_stack.Count > 1)
					{
						prelayer_stack.RemoveAt(prelayer_stack.Count - 1);
						prelayer = prelayers[prelayer_stack[prelayer_stack.Count - 1]];
						generate_error = false;
						result = 2;
						break;
					}
					if (generate_world_mode)
					{
						generate = false;
						for (num = 0; num < terrains.Count; num++)
						{
							terrain_apply(terrains[num]);
						}
					}
					generate_time = Time.realtimeSinceStartup - generate_time_start;
					if (generate)
					{
						prelayer3.count_terrain++;
						if (find_terrain(first: false))
						{
							preterrain = terrains[prelayer3.count_terrain];
							generate_terrain_start();
						}
						else
						{
							generate = false;
							generateDone = true;
						}
					}
					generate_error = false;
					result = 2;
					break;
				}
				if (generate_world_mode || prelayer3.index > 0)
				{
					for (num = 0; num < terrains.Count; num++)
					{
						if (terrains[num].rect.Contains(new Vector2(terrains[num].prearea.area.x, y)))
						{
							terrains[num].on_row = true;
						}
						else
						{
							terrains[num].on_row = false;
						}
					}
				}
				prelayer3.x = prelayer3.prearea.area.x + prelayer3.break_x_value;
				for (; prelayer3.x <= prelayer3.prearea.area.xMax; prelayer3.x += prelayer3.prearea.step.x)
				{
					float x = prelayer3.x;
					float num2 = default(float);
					float num3 = default(float);
					float num4 = default(float);
					float num5 = prelayer3.counter_y;
					if (generate_world_mode || prelayer3.index > 0)
					{
						bool flag = true;
						for (num = 0; num < terrains.Count; num++)
						{
							if (terrains[num].rect.Contains(new Vector2(x, num5)))
							{
								flag = false;
								preterrain = terrains[num];
								break;
							}
						}
						if (flag)
						{
							continue;
						}
						if (prelayer3.prearea.rotation_active)
						{
							Vector2 vector = calc_rotation_pixel(x, num5, prelayer3.prearea.center.x, prelayer3.prearea.center.y, prelayer3.prearea.rotation.y);
							x = vector.x;
							num5 = vector.y;
						}
					}
					local_x = x - preterrain.rect.x;
					local_y = num5 - preterrain.rect.y;
					local_x_rot = x - preterrain.rect.x;
					local_y_rot = num5 - preterrain.rect.y;
					if (settings.showTerrains)
					{
						degree = calc_terrain_angle(preterrain, local_x_rot, local_y_rot, settings.smooth_angle) * settings.global_degree_strength + settings.global_degree_level;
						height = preterrain.terrain.terrainData.GetHeight((int)(local_x_rot / preterrain.heightmap_conversion.x), (int)(local_y_rot / preterrain.heightmap_conversion.y)) / preterrain.size.y * settings.global_height_strength + settings.global_height_level;
					}
					random_range = UnityEngine.Random.Range(0f, 1000f);
					int i;
					for (i = 0; i < prelayer3.layer.Count; i++)
					{
						current_layer = prelayer3.layer[i];
						filter_value = 0f;
						filter_strength = 1f;
						layer_x = local_x_rot;
						layer_y = local_y_rot;
					}
					for (int j = 0; j < current_layer.prefilter.filter_index.Count; j++)
					{
						calc_filter_value(filter[current_layer.prefilter.filter_index[j]], num5, x);
					}
					if (subfilter_value * current_layer.strength * filter_strength <= 0f)
					{
						continue;
					}
					int index = (int)(current_layer.object_output.object_value.curve.Evaluate(filter_value) * (float)current_layer.object_output.@object.Count);
					object_class = current_layer.object_output.@object[index];
					if (current_layer.positionSeed)
					{
						if (num5 == 0f || x == 0f)
						{
							UnityEngine.Random.seed = (int)((float)(seed - 10) + (num5 + 1f) * (x + 1f) + (float)(10000000 * (i + 1)));
						}
						else
						{
							UnityEngine.Random.seed = (int)((float)(seed - 10) + num5 * x * (float)(i + 1));
						}
					}
					random_range2 = UnityEngine.Random.Range(0f, 1f);
					if (!(random_range2 <= subfilter_value * current_layer.strength * filter_strength))
					{
						continue;
					}
					place = true;
					bool flag2 = true;
					lhs = Quaternion.identity;
					int num6 = default(int);
					position = new Vector3(x, 0f, num5);
					Vector3 position_start = object_class.position_start;
					Vector3 position_end = object_class.position_end;
					Vector3 vector2 = default(Vector3);
					vector2.x = UnityEngine.Random.Range(position_start.x, position_end.x);
					vector2.y = UnityEngine.Random.Range(position_start.y, position_end.y);
					vector2.z = UnityEngine.Random.Range(position_start.z, position_end.z);
					if (object_class.random_position)
					{
						vector2.x += UnityEngine.Random.Range(0f - prelayer3.prearea.step.x, prelayer3.prearea.step.x);
						vector2.z += UnityEngine.Random.Range(0f - prelayer3.prearea.step.y, prelayer3.prearea.step.y);
					}
					position += vector2;
					if (object_class.terrain_rotate)
					{
						Vector3 interpolatedNormal = preterrain.terrain.terrainData.GetInterpolatedNormal((local_x_rot + vector2.x) / preterrain.size.x, (local_y_rot + vector2.y) / preterrain.size.z);
						interpolatedNormal.x = interpolatedNormal.x / 3f * 2f;
						interpolatedNormal.z = interpolatedNormal.z / 3f * 2f;
						lhs = Quaternion.FromToRotation(Vector3.up, interpolatedNormal);
					}
					lhs *= Quaternion.AngleAxis(UnityEngine.Random.Range(object_class.rotation_start.x, object_class.rotation_end.x), Vector3.right);
					lhs *= Quaternion.AngleAxis(UnityEngine.Random.Range(object_class.rotation_start.y, object_class.rotation_end.y), Vector3.up);
					lhs *= Quaternion.AngleAxis(UnityEngine.Random.Range(object_class.rotation_start.z, object_class.rotation_end.z), Vector3.forward);
					lhs *= Quaternion.Euler(object_class.parent_rotation);
					if (object_class.terrain_height)
					{
						height_interpolated = preterrain.terrain.terrainData.GetInterpolatedHeight((local_x_rot + vector2.x) / preterrain.size.x, (local_y_rot + vector2.z) / preterrain.size.z);
						ref Vector3 reference = ref position;
						float num7 = height_interpolated;
						Vector3 vector3 = preterrain.terrain.transform.position;
						reference.y = num7 + vector3.y + vector2.y;
					}
					float num8 = object_class.scale_end.x - object_class.scale_start.x;
					scale.x = UnityEngine.Random.Range(object_class.scale_start.x, object_class.scale_end.x);
					float num9 = scale.x - object_class.scale_start.x;
					float num10 = num9 / num8;
					float num11 = object_class.scale_end.y - object_class.scale_start.y;
					float num12 = num11 * num10 - object_class.unlink_y * num9 + object_class.scale_start.y;
					if (!(num12 >= object_class.scale_start.y))
					{
						num12 = object_class.scale_start.y;
					}
					float num13 = num11 * num10 + object_class.unlink_y * num9 + object_class.scale_start.y;
					if (!(num13 <= object_class.scale_end.y))
					{
						num13 = object_class.scale_end.y;
					}
					scale.y = UnityEngine.Random.Range(num12, num13);
					float num14 = object_class.scale_end.z - object_class.scale_start.z;
					float num15 = num14 * num10 - object_class.unlink_z * num9 + object_class.scale_start.z;
					if (!(num15 >= object_class.scale_start.z))
					{
						num15 = object_class.scale_start.z;
					}
					float num16 = num14 * num10 + object_class.unlink_z * num9 + object_class.scale_start.z;
					if (!(num16 <= object_class.scale_end.z))
					{
						num16 = object_class.scale_end.z;
					}
					scale.z = UnityEngine.Random.Range(num15, num16);
					if (object_class.raycast && Physics.SphereCast(position + new Vector3(0f, object_class.cast_height, 0f), object_class.ray_radius, object_class.ray_direction, out hit, object_class.ray_length))
					{
						layerHit = (int)Mathf.Pow(2f, hit.transform.gameObject.layer);
						if ((layerHit & object_class.layerMask) != 0)
						{
							ref Vector3 reference2 = ref position;
							Vector3 point = hit.point;
							reference2.y = point.y;
						}
					}
					if (object_class.pivot_center)
					{
						position.y += scale.y / 2f;
					}
					bool flag3 = false;
					scale *= current_layer.object_output.scale;
					if (!place)
					{
						continue;
					}
					float z = preterrain.size.z;
					z /= preterrain.heightmap_resolution;
					object_class.placed++;
					object_class.placed_prelayer++;
					current_layer.object_output.placed = current_layer.object_output.placed + 1;
					row_object_count++;
					if (!object_class.prelayer_created || !prelayers[object_class.prelayer_index].prearea.active)
					{
						continue;
					}
					goto IL_0c9d;
				}
				prelayer3.counter_y -= prelayer.prearea.step.y;
				continue;
			}
			prelayer3.y -= (float)(generate_speed + 1) * prelayer.prearea.step.y;
			generate_time = Time.realtimeSinceStartup - generate_time_start;
			result = 1;
			break;
			IL_0c9d:
			set_object_child(object_class, lhs.eulerAngles);
			prelayer3.x += prelayer3.prearea.step.x;
			prelayer3.y = prelayer3.counter_y;
			if (!(prelayer3.x > prelayer.prearea.area.xMax))
			{
				prelayer3.break_x_value = prelayer3.x - prelayer3.prearea.area.x;
			}
			else
			{
				prelayer3.y -= prelayer3.prearea.step.y;
				prelayer3.break_x_value = 0f;
			}
			prelayer_stack.Add(object_class.prelayer_index);
			prelayer = prelayers[object_class.prelayer_index];
			prelayer.prearea.area.x = position.x + prelayer.prearea.area_old.x * scale.x;
			prelayer.prearea.area.y = position.z + prelayer.prearea.area_old.y * scale.z;
			prelayer.prearea.area.width = prelayer.prearea.area_old.width * scale.x;
			prelayer.prearea.area.height = prelayer.prearea.area_old.height * scale.z;
			if (lhs.y != 0f)
			{
				prelayer.prearea.rotation = lhs.eulerAngles;
				prelayer.prearea.rotation_active = true;
			}
			prelayer.prearea.step.y = Mathf.Sqrt(Mathf.Pow(prelayer.prearea.step_old.x, 2f) + Mathf.Pow(prelayer.prearea.step_old.y, 2f)) / 2f;
			prelayer.prearea.step.x = prelayer.prearea.step.y;
			prelayer.prearea.center = new Vector2(position.x, position.z);
			prelayer.y = prelayer.prearea.area.yMax;
			result = 3;
			break;
		}
		return result;
	}

	public string convert_terrains_to_mesh()
	{
		GameObject gameObject = null;
		GameObject gameObject2 = null;
		List<vertex_class> list = new List<vertex_class>();
		int num = default(int);
		int num2 = default(int);
		int num3 = default(int);
		List<Mesh> list2 = new List<Mesh>();
		int num4 = default(int);
		int num5 = default(int);
		terrain_class terrain_class = terrains[0];
		normal_class normal_class = null;
		Vector3 vector = default(Vector3);
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		int num6 = 0;
		num3 = 0;
		object result;
		while (true)
		{
			if (num3 < terrains.Count)
			{
				if (!terrains[num3].terrain)
				{
					result = "All terrains must be assigned";
					break;
				}
				if (!terrains[num3].terrain.terrainData)
				{
					result = "All terrainData's must be assigned";
					break;
				}
				if (terrains[num3].terrain.terrainData.heightmapResolution > 129)
				{
					result = "Can only convert 33, 65 and 129 heightmap resolution at the moment";
					break;
				}
				if (terrains[num3].active)
				{
					num6++;
				}
				num3++;
				continue;
			}
			if (num6 == 0)
			{
				result = "Please activate at least 1 terrain";
				break;
			}
			num6 = 0;
			gameObject = new GameObject();
			gameObject.name = "Terrains Mesh";
			for (num3 = 0; num3 < terrains.Count; num3++)
			{
				if (terrains[num3].active)
				{
					num2 = terrains[num3].terrain.terrainData.heightmapResolution;
					Vector3 size = terrain_class.terrain.terrainData.size;
					vector.x = size.x / (float)(num2 - 1);
					Vector3 size2 = terrain_class.terrain.terrainData.size;
					vector.z = size2.z / (float)(num2 - 1);
					Vector3 size3 = terrain_class.terrain.terrainData.size;
					vector.y = size3.y;
					terrains[num3].index = num3;
					list2.Add(convert_terrain_to_mesh(terrains[num3], gameObject));
					list.Add(new vertex_class());
					list[num6].vertices = list2[num6].vertices;
					num6++;
				}
			}
			Mesh mesh = null;
			result = "Converting " + 0.ToString() + " terrains to meshes done";
			break;
		}
		return (string)result;
	}

	public Mesh convert_terrain_to_mesh(terrain_class preterrain1, GameObject parent)
	{
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		object result;
		if ((bool)preterrain1.terrain && (bool)preterrain1.terrain.terrainData)
		{
			int heightmapResolution = preterrain1.terrain.terrainData.heightmapResolution;
			int num = heightmapResolution * heightmapResolution;
			Vector3[] array = new Vector3[num];
			int num2 = 0;
			Vector2[] array2 = new Vector2[array.Length];
			Vector3 size = preterrain1.terrain.terrainData.size;
			float num3 = size.x / (float)(heightmapResolution - 1);
			Vector3 size2 = preterrain1.terrain.terrainData.size;
			float num4 = size2.z / (float)(heightmapResolution - 1);
			Vector3 size3 = preterrain1.terrain.terrainData.size;
			float y = size3.y;
			int num5 = default(int);
			int num6 = default(int);
			Vector3 size4 = preterrain1.terrain.terrainData.size;
			float y2 = size4.y;
			Vector3 vector = preterrain1.terrain.transform.position;
			for (num5 = 0; num5 < heightmapResolution; num5++)
			{
				for (num6 = 0; num6 < heightmapResolution; num6++)
				{
					array[num2] = new Vector3((float)num6 * num3, preterrain1.terrain.terrainData.GetHeight(num6, num5), (float)num5 * num4);
					Vector2[] array3 = array2;
					int num7;
					num2 = (num7 = num2) + 1;
					array3[num7] = new Vector2((float)num6 * 1f / (float)heightmapResolution, (float)num5 * 1f / (float)heightmapResolution);
				}
			}
			int[] array4 = new int[array.Length * 6];
			int num8 = 0;
			int num9 = default(int);
			int num10 = default(int);
			for (num5 = 0; num5 < heightmapResolution - 1; num5++)
			{
				for (num6 = 0; num6 < heightmapResolution - 1; num6++)
				{
					num9 = num5 * heightmapResolution + num6;
					int[] array5 = array4;
					int num11;
					num8 = (num11 = num8) + 1;
					array5[num11] = num9 + 1;
					int[] array6 = array4;
					int num12;
					num8 = (num12 = num8) + 1;
					array6[num12] = num9;
					int[] array7 = array4;
					int num13;
					num8 = (num13 = num8) + 1;
					array7[num13] = num9 + heightmapResolution;
					int[] array8 = array4;
					int num14;
					num8 = (num14 = num8) + 1;
					array8[num14] = num9 + 1;
					int[] array9 = array4;
					int num15;
					num8 = (num15 = num8) + 1;
					array9[num15] = num9 + heightmapResolution;
					int[] array10 = array4;
					int num16;
					num8 = (num16 = num8) + 1;
					array10[num16] = num9 + heightmapResolution + 1;
				}
			}
			GameObject gameObject = new GameObject();
			gameObject.transform.position = preterrain1.terrain.transform.position;
			gameObject.transform.parent = parent.transform;
			gameObject.name = preterrain1.name;
			Mesh mesh = new Mesh();
			MeshFilter meshFilter = (MeshFilter)gameObject.AddComponent(typeof(MeshFilter));
			MeshRenderer meshRenderer = (MeshRenderer)gameObject.AddComponent(typeof(MeshRenderer));
			meshRenderer.material = settings.mesh_material;
			meshFilter.mesh = mesh;
			mesh.vertices = array;
			mesh.triangles = array4;
			mesh.uv = array2;
			float num17 = Time.realtimeSinceStartup - realtimeSinceStartup;
			float num18 = Time.realtimeSinceStartup - realtimeSinceStartup;
			result = mesh;
		}
		else
		{
			result = null;
		}
		return (Mesh)result;
	}

	public normal_class calc_normal(float space, vertex_class vertex, int pos, int resolution)
	{
		normal_class normal_class = new normal_class();
		Vector3 vector = default(Vector3);
		Vector3 vector2 = default(Vector3);
		Vector3 vector3 = default(Vector3);
		Vector3 vector4 = default(Vector3);
		Vector3 vector5 = default(Vector3);
		Vector3 vector6 = default(Vector3);
		Vector3 vector7 = default(Vector3);
		Vector3 vector8 = default(Vector3);
		Vector3 vector9 = default(Vector3);
		Vector3 vector10 = default(Vector3);
		Vector4 vector11 = default(Vector4);
		float num = default(float);
		float num2 = default(float);
		vector = vertex.vertices[pos];
		vector2 = vertex.vertices[pos - resolution - 1];
		vector3 = vertex.vertices[pos - resolution];
		vector4 = vertex.vertices[pos - resolution + 1];
		vector5 = vertex.vertices[pos - 1];
		vector6 = vertex.vertices[pos + 1];
		vector7 = vertex.vertices[pos + resolution - 1];
		vector8 = vertex.vertices[pos + resolution];
		vector9 = vertex.vertices[pos + resolution + 1];
		vector10 = Vector3.Cross(vector2 - vector, vector3 - vector);
		vector10 += Vector3.Cross(vector3 - vector, vector4 - vector);
		vector10 += Vector3.Cross(vector5 - vector, vector2 - vector);
		vector10 += Vector3.Cross(vector4 - vector, vector6 - vector);
		vector10 += Vector3.Cross(vector7 - vector, vector5 - vector);
		vector10 += Vector3.Cross(vector6 - vector, vector9 - vector);
		vector10 += Vector3.Cross(vector8 - vector, vector7 - vector);
		vector10 += Vector3.Cross(vector9 - vector, vector8 - vector);
		vector10 = (vector10 / 8f).normalized;
		vector10.y *= -1f;
		normal_class.normal = vector10;
		num = vector5.y;
		num2 = vector6.y;
		normal_class.tangent = new Vector4(0f - space, num2 - num, 0f, 0f - space).normalized;
		return normal_class;
	}

	public normal_class calc_normal_border_left(terrain_class preterrain1, float space, List<vertex_class> vertex, int y, int resolution, Vector3 size)
	{
		normal_class normal_class = new normal_class();
		Vector3 vector = default(Vector3);
		Vector3 vector2 = default(Vector3);
		Vector3 vector3 = default(Vector3);
		Vector3 vector4 = default(Vector3);
		Vector3 vector5 = default(Vector3);
		Vector3 vector6 = default(Vector3);
		Vector3 vector7 = default(Vector3);
		Vector3 vector8 = default(Vector3);
		Vector3 vector9 = default(Vector3);
		bool flag = true;
		bool flag2 = true;
		bool flag3 = true;
		bool flag4 = true;
		bool flag5 = true;
		bool flag6 = true;
		bool flag7 = true;
		Vector3 vector10 = Vector3.zero;
		Vector4 vector11 = default(Vector4);
		float num = default(float);
		float num2 = default(float);
		float num3 = 0f;
		vector = vertex[preterrain1.index].vertices[y * resolution];
		if (preterrain1.neighbor.left > -1)
		{
			vector2 = vertex[preterrain1.neighbor.left].vertices[resolution - 2 + (y - 1) * resolution] - new Vector3(size.x, 0f, 0f);
			vector5 = vertex[preterrain1.neighbor.left].vertices[resolution - 2 + y * resolution] - new Vector3(size.x, 0f, 0f);
			vector7 = vertex[preterrain1.neighbor.left].vertices[resolution - 2 + (y + 1) * resolution] - new Vector3(size.x, 0f, 0f);
		}
		else
		{
			flag = false;
			flag4 = false;
			flag5 = false;
		}
		vector3 = vertex[preterrain1.index].vertices[(y - 1) * resolution];
		vector4 = vertex[preterrain1.index].vertices[1 + (y - 1) * resolution];
		vector8 = vertex[preterrain1.index].vertices[(y + 1) * resolution];
		vector9 = vertex[preterrain1.index].vertices[1 + (y + 1) * resolution];
		vector6 = vertex[preterrain1.index].vertices[1 + y * resolution];
		if (flag && flag2)
		{
			vector10 = Vector3.Cross(vector2 - vector, vector3 - vector);
			num3 += 1f;
		}
		if (flag2 && flag3)
		{
			vector10 += Vector3.Cross(vector3 - vector, vector4 - vector);
			num3 += 1f;
		}
		if (flag4 && flag)
		{
			vector10 += Vector3.Cross(vector5 - vector, vector2 - vector);
			num3 += 1f;
		}
		if (flag3)
		{
			vector10 += Vector3.Cross(vector4 - vector, vector6 - vector);
			num3 += 1f;
		}
		if (flag5 && flag4)
		{
			vector10 += Vector3.Cross(vector7 - vector, vector5 - vector);
			num3 += 1f;
		}
		if (flag7)
		{
			vector10 += Vector3.Cross(vector6 - vector, vector9 - vector);
			num3 += 1f;
		}
		if (flag5 && flag6)
		{
			vector10 += Vector3.Cross(vector8 - vector, vector7 - vector);
			num3 += 1f;
		}
		if (flag6 && flag7)
		{
			vector10 += Vector3.Cross(vector9 - vector, vector8 - vector);
			num3 += 1f;
		}
		vector10 = (vector10 / num3).normalized;
		vector10.y *= -1f;
		normal_class.normal = vector10;
		num = ((!flag4) ? vector.y : vector5.y);
		num2 = vector6.y;
		normal_class.tangent = new Vector4(0f - space, num2 - num, 0f, 0f - space).normalized;
		return normal_class;
	}

	public normal_class calc_normal_border_right(terrain_class preterrain1, float space, List<vertex_class> vertex, int y, int resolution, Vector3 size)
	{
		normal_class normal_class = new normal_class();
		Vector3 vector = default(Vector3);
		Vector3 vector2 = default(Vector3);
		Vector3 vector3 = default(Vector3);
		Vector3 vector4 = default(Vector3);
		Vector3 vector5 = default(Vector3);
		Vector3 vector6 = default(Vector3);
		Vector3 vector7 = default(Vector3);
		Vector3 vector8 = default(Vector3);
		Vector3 vector9 = default(Vector3);
		bool flag = true;
		bool flag2 = true;
		bool flag3 = true;
		bool flag4 = true;
		bool flag5 = true;
		bool flag6 = true;
		bool flag7 = true;
		Vector3 vector10 = Vector3.zero;
		Vector4 vector11 = default(Vector4);
		float num = default(float);
		float num2 = default(float);
		float num3 = 0f;
		if (preterrain1.neighbor.right > -1)
		{
			vector4 = vertex[preterrain1.neighbor.right].vertices[1 + (y - 1) * resolution] + new Vector3(size.x, 0f, 0f);
			vector6 = vertex[preterrain1.neighbor.right].vertices[1 + y * resolution] + new Vector3(size.x, 0f, 0f);
			vector9 = vertex[preterrain1.neighbor.right].vertices[1 + (y + 1) * resolution] + new Vector3(size.x, 0f, 0f);
		}
		else
		{
			flag3 = false;
			flag4 = false;
			flag7 = false;
		}
		vector2 = vertex[preterrain1.index].vertices[resolution - 2 + (y - 1) * resolution];
		vector3 = vertex[preterrain1.index].vertices[resolution - 1 + (y - 1) * resolution];
		vector7 = vertex[preterrain1.index].vertices[resolution - 2 + (y + 1) * resolution];
		vector8 = vertex[preterrain1.index].vertices[resolution - 1 + (y + 1) * resolution];
		vector = vertex[preterrain1.index].vertices[resolution - 1 + y * resolution];
		vector5 = vertex[preterrain1.index].vertices[resolution - 2 + y * resolution];
		if (flag && flag2)
		{
			vector10 = Vector3.Cross(vector2 - vector, vector3 - vector);
			num3 += 1f;
		}
		if (flag2 && flag3)
		{
			vector10 += Vector3.Cross(vector3 - vector, vector4 - vector);
			num3 += 1f;
		}
		if (flag)
		{
			vector10 += Vector3.Cross(vector5 - vector, vector2 - vector);
			num3 += 1f;
		}
		if (flag3 && flag4)
		{
			vector10 += Vector3.Cross(vector4 - vector, vector6 - vector);
			num3 += 1f;
		}
		if (flag5)
		{
			vector10 += Vector3.Cross(vector7 - vector, vector5 - vector);
			num3 += 1f;
		}
		if (flag4 && flag7)
		{
			vector10 += Vector3.Cross(vector6 - vector, vector9 - vector);
			num3 += 1f;
		}
		if (flag5 && flag6)
		{
			vector10 += Vector3.Cross(vector8 - vector, vector7 - vector);
			num3 += 1f;
		}
		if (flag7 && flag6)
		{
			vector10 += Vector3.Cross(vector9 - vector, vector8 - vector);
			num3 += 1f;
		}
		vector10 = (vector10 / num3).normalized;
		vector10.y *= -1f;
		normal_class.normal = vector10;
		num = vector5.y;
		num2 = ((!flag4) ? vector.y : vector6.y);
		normal_class.tangent = new Vector4(0f - space, num2 - num, 0f, 0f - space).normalized;
		return normal_class;
	}

	public normal_class calc_normal_border_top(terrain_class preterrain1, float space, List<vertex_class> vertex, int x, int resolution, Vector3 size)
	{
		normal_class normal_class = new normal_class();
		Vector3 vector = default(Vector3);
		Vector3 vector2 = default(Vector3);
		Vector3 vector3 = default(Vector3);
		Vector3 vector4 = default(Vector3);
		Vector3 vector5 = default(Vector3);
		Vector3 vector6 = default(Vector3);
		Vector3 vector7 = default(Vector3);
		Vector3 vector8 = default(Vector3);
		Vector3 vector9 = default(Vector3);
		bool flag = true;
		bool flag2 = true;
		bool flag3 = true;
		bool flag4 = true;
		bool flag5 = true;
		bool flag6 = true;
		bool flag7 = true;
		Vector3 vector10 = Vector3.zero;
		Vector4 vector11 = default(Vector4);
		float num = default(float);
		float num2 = default(float);
		float num3 = 0f;
		if (x + 1 > resolution - 1)
		{
			if (preterrain1.neighbor.right > -1)
			{
				vector6 = vertex[preterrain1.neighbor.right].vertices[1 + resolution * (resolution - 1)] + new Vector3(size.x, 0f, 0f);
				vector4 = vertex[preterrain1.neighbor.right].vertices[1 + resolution * (resolution - 2)] + new Vector3(size.x, 0f, 0f);
				if (preterrain1.neighbor.top_right > -1)
				{
					vector9 = vertex[preterrain1.neighbor.top_right].vertices[resolution + 1] + new Vector3(size.x, 0f, size.z);
				}
				else
				{
					flag7 = false;
				}
			}
			else
			{
				flag2 = false;
				flag4 = false;
				flag7 = false;
			}
			if (preterrain1.neighbor.top > -1)
			{
				vector7 = vertex[preterrain1.neighbor.top].vertices[x - 1 + resolution] + new Vector3(0f, 0f, size.z);
				vector8 = vertex[preterrain1.neighbor.top].vertices[x + resolution] + new Vector3(0f, 0f, size.z);
			}
			else
			{
				flag5 = false;
				flag6 = false;
			}
			vector2 = vertex[preterrain1.index].vertices[x - 1 + resolution * (resolution - 2)];
			vector5 = vertex[preterrain1.index].vertices[x - 1 + resolution * (resolution - 1)];
		}
		else if (x - 1 < 0)
		{
			if (preterrain1.neighbor.left > -1)
			{
				vector2 = vertex[preterrain1.neighbor.left].vertices[resolution - 2 + resolution * (resolution - 2)] - new Vector3(size.x, 0f, 0f);
				vector5 = vertex[preterrain1.neighbor.left].vertices[resolution - 2 + resolution * (resolution - 1)] - new Vector3(size.x, 0f, 0f);
				if (preterrain1.neighbor.top_left > -1)
				{
					vector7 = vertex[preterrain1.neighbor.top_left].vertices[resolution - 2 + resolution] - new Vector3(size.x, 0f, 0f - size.z);
				}
				else
				{
					flag5 = false;
				}
			}
			else
			{
				flag = false;
				flag3 = false;
				flag5 = false;
			}
			if (preterrain1.neighbor.top > -1)
			{
				vector8 = vertex[preterrain1.neighbor.top].vertices[x + resolution] + new Vector3(0f, 0f, size.z);
				vector9 = vertex[preterrain1.neighbor.top].vertices[x + 1 + resolution] + new Vector3(0f, 0f, size.z);
			}
			else
			{
				flag6 = false;
				flag7 = false;
			}
			vector4 = vertex[preterrain1.index].vertices[x + 1 + resolution * (resolution - 2)];
			vector6 = vertex[preterrain1.index].vertices[x + 1 + resolution * (resolution - 1)];
		}
		else
		{
			if (preterrain1.neighbor.top > -1)
			{
				vector7 = vertex[preterrain1.neighbor.top].vertices[x - 1 + resolution] + new Vector3(0f, 0f, size.z);
				vector8 = vertex[preterrain1.neighbor.top].vertices[x + resolution] + new Vector3(0f, 0f, size.z);
				vector9 = vertex[preterrain1.neighbor.top].vertices[x + 1 + resolution] + new Vector3(0f, 0f, size.z);
			}
			else
			{
				flag5 = false;
				flag6 = false;
				flag7 = false;
			}
			vector2 = vertex[preterrain1.index].vertices[x - 1 + resolution * (resolution - 2)];
			vector4 = vertex[preterrain1.index].vertices[x + 1 + resolution * (resolution - 2)];
			vector5 = vertex[preterrain1.index].vertices[x - 1 + resolution * (resolution - 1)];
			vector6 = vertex[preterrain1.index].vertices[x + 1 + resolution * (resolution - 1)];
		}
		vector = vertex[preterrain1.index].vertices[x + resolution * (resolution - 1)];
		vector3 = vertex[preterrain1.index].vertices[x + resolution * (resolution - 2)];
		if (flag)
		{
			vector10 = Vector3.Cross(vector2 - vector, vector3 - vector);
			num3 += 1f;
		}
		if (flag2)
		{
			vector10 += Vector3.Cross(vector3 - vector, vector4 - vector);
			num3 += 1f;
		}
		if (flag && flag3)
		{
			vector10 += Vector3.Cross(vector5 - vector, vector2 - vector);
			num3 += 1f;
		}
		if (flag2 && flag4)
		{
			vector10 += Vector3.Cross(vector4 - vector, vector6 - vector);
			num3 += 1f;
		}
		if (flag5 && flag3)
		{
			vector10 += Vector3.Cross(vector7 - vector, vector5 - vector);
			num3 += 1f;
		}
		if (flag4 && flag7)
		{
			vector10 += Vector3.Cross(vector6 - vector, vector9 - vector);
			num3 += 1f;
		}
		if (flag5 && flag6)
		{
			vector10 += Vector3.Cross(vector8 - vector, vector7 - vector);
			num3 += 1f;
		}
		if (flag7 && flag6)
		{
			vector10 += Vector3.Cross(vector9 - vector, vector8 - vector);
			num3 += 1f;
		}
		vector10 = (vector10 / num3).normalized;
		vector10.y *= -1f;
		normal_class.normal = vector10;
		num = ((!flag3) ? vector.y : vector5.y);
		num2 = ((!flag4) ? vector.y : vector6.y);
		normal_class.tangent = new Vector4(0f - space, num2 - num, 0f, 0f - space).normalized;
		return normal_class;
	}

	public normal_class calc_normal_border_bottom(terrain_class preterrain1, float space, List<vertex_class> vertex, int x, int resolution, Vector3 size)
	{
		normal_class normal_class = new normal_class();
		Vector3 vector = default(Vector3);
		Vector3 vector2 = default(Vector3);
		Vector3 vector3 = default(Vector3);
		Vector3 vector4 = default(Vector3);
		Vector3 vector5 = default(Vector3);
		Vector3 vector6 = default(Vector3);
		Vector3 vector7 = default(Vector3);
		Vector3 vector8 = default(Vector3);
		Vector3 vector9 = default(Vector3);
		bool flag = true;
		bool flag2 = true;
		bool flag3 = true;
		bool flag4 = true;
		bool flag5 = true;
		bool flag6 = true;
		bool flag7 = true;
		Vector3 vector10 = Vector3.zero;
		Vector4 vector11 = default(Vector4);
		float num = default(float);
		float num2 = default(float);
		float num3 = 0f;
		if (x + 1 > resolution - 1)
		{
			if (preterrain1.neighbor.right > -1)
			{
				vector6 = vertex[preterrain1.neighbor.right].vertices[1] + new Vector3(size.x, 0f, 0f);
				vector9 = vertex[preterrain1.neighbor.right].vertices[1 + resolution] + new Vector3(size.x, 0f, 0f);
				if (preterrain1.neighbor.bottom_right > -1)
				{
					vector4 = vertex[preterrain1.neighbor.bottom_right].vertices[1 + resolution * (resolution - 2)] + new Vector3(size.x, 0f, 0f - size.z);
				}
				else
				{
					flag3 = false;
				}
			}
			else
			{
				flag3 = false;
				flag5 = false;
				flag7 = false;
			}
			if (preterrain1.neighbor.bottom > -1)
			{
				vector2 = vertex[preterrain1.neighbor.bottom].vertices[x - 1 + resolution * (resolution - 2)] - new Vector3(0f, 0f, size.z);
				vector3 = vertex[preterrain1.neighbor.bottom].vertices[x + resolution * (resolution - 2)] - new Vector3(0f, 0f, size.z);
			}
			else
			{
				flag = false;
				flag2 = false;
			}
			vector7 = vertex[preterrain1.index].vertices[x - 1 + resolution];
			vector5 = vertex[preterrain1.index].vertices[x - 1];
		}
		else if (x - 1 < 0)
		{
			if (preterrain1.neighbor.left > -1)
			{
				vector7 = vertex[preterrain1.neighbor.left].vertices[resolution - 2 + resolution] - new Vector3(size.x, 0f, 0f);
				vector5 = vertex[preterrain1.neighbor.left].vertices[resolution - 2] - new Vector3(size.x, 0f, 0f);
				if (preterrain1.neighbor.bottom_left > -1)
				{
					vector2 = vertex[preterrain1.neighbor.bottom_left].vertices[resolution - 2 + resolution * (resolution - 2)] - new Vector3(size.x, 0f, size.z);
				}
				else
				{
					flag = false;
				}
			}
			else
			{
				flag = false;
				flag4 = false;
				flag6 = false;
			}
			if (preterrain1.neighbor.bottom > -1)
			{
				vector3 = vertex[preterrain1.neighbor.bottom].vertices[x + resolution * (resolution - 2)] - new Vector3(0f, 0f, size.z);
				vector4 = vertex[preterrain1.neighbor.bottom].vertices[x + 1 + resolution * (resolution - 2)] - new Vector3(0f, 0f, size.z);
			}
			else
			{
				flag2 = false;
				flag3 = false;
			}
			vector9 = vertex[preterrain1.index].vertices[x + 1 + resolution];
			vector6 = vertex[preterrain1.index].vertices[x + 1];
		}
		else
		{
			if (preterrain1.neighbor.bottom > -1)
			{
				vector2 = vertex[preterrain1.neighbor.bottom].vertices[x - 1 + resolution * (resolution - 2)] - new Vector3(0f, 0f, size.z);
				vector3 = vertex[preterrain1.neighbor.bottom].vertices[x + resolution * (resolution - 2)] - new Vector3(0f, 0f, size.z);
				vector4 = vertex[preterrain1.neighbor.bottom].vertices[x + 1 + resolution * (resolution - 2)] - new Vector3(0f, 0f, size.z);
			}
			else
			{
				flag = false;
				flag2 = false;
				flag3 = false;
			}
			vector7 = vertex[preterrain1.index].vertices[x - 1 + resolution];
			vector9 = vertex[preterrain1.index].vertices[x + 1 + resolution];
			vector5 = vertex[preterrain1.index].vertices[x - 1];
			vector6 = vertex[preterrain1.index].vertices[x + 1];
		}
		vector = vertex[preterrain1.index].vertices[x];
		vector8 = vertex[preterrain1.index].vertices[x + resolution];
		if (flag && flag2)
		{
			vector10 = Vector3.Cross(vector2 - vector, vector3 - vector);
			num3 += 1f;
		}
		if (flag3 && flag2)
		{
			vector10 += Vector3.Cross(vector3 - vector, vector4 - vector);
			num3 += 1f;
		}
		if (flag && flag4)
		{
			vector10 += Vector3.Cross(vector5 - vector, vector2 - vector);
			num3 += 1f;
		}
		if (flag3 && flag5)
		{
			vector10 += Vector3.Cross(vector4 - vector, vector6 - vector);
			num3 += 1f;
		}
		if (flag6 && flag4)
		{
			vector10 += Vector3.Cross(vector7 - vector, vector5 - vector);
			num3 += 1f;
		}
		if (flag5 && flag7)
		{
			vector10 += Vector3.Cross(vector6 - vector, vector9 - vector);
			num3 += 1f;
		}
		if (flag6)
		{
			vector10 += Vector3.Cross(vector8 - vector, vector7 - vector);
			num3 += 1f;
		}
		if (flag7)
		{
			vector10 += Vector3.Cross(vector9 - vector, vector8 - vector);
			num3 += 1f;
		}
		vector10 = (vector10 / num3).normalized;
		vector10.y *= -1f;
		normal_class.normal = vector10;
		num = ((!flag4) ? vector.y : vector5.y);
		num2 = ((!flag5) ? vector.y : vector6.y);
		normal_class.tangent = new Vector4(0f - space, num2 - num, 0f, 0f - space).normalized;
		return normal_class;
	}

	public void set_terrains_neighbor()
	{
		int num = default(int);
		for (int i = 0; i < terrains.Count; i++)
		{
			if ((bool)terrains[i].terrain)
			{
				num = search_tile((int)(terrains[i].tile_x - 1f), (int)terrains[i].tile_z);
				if (num != -1)
				{
					terrains[i].neighbor.left = num;
				}
				else
				{
					terrains[i].neighbor.left = -1;
				}
				num = search_tile((int)terrains[i].tile_x, (int)(terrains[i].tile_z - 1f));
				if (num != -1)
				{
					terrains[i].neighbor.top = num;
				}
				else
				{
					terrains[i].neighbor.top = -1;
				}
				num = search_tile((int)(terrains[i].tile_x + 1f), (int)terrains[i].tile_z);
				if (num != -1)
				{
					terrains[i].neighbor.right = num;
				}
				else
				{
					terrains[i].neighbor.right = -1;
				}
				num = search_tile((int)terrains[i].tile_x, (int)(terrains[i].tile_z + 1f));
				if (num != -1)
				{
					terrains[i].neighbor.bottom = num;
				}
				else
				{
					terrains[i].neighbor.bottom = -1;
				}
				num = search_tile((int)(terrains[i].tile_x + 1f), (int)(terrains[i].tile_z + 1f));
				if (num != -1)
				{
					terrains[i].neighbor.bottom_right = num;
				}
				else
				{
					terrains[i].neighbor.bottom_right = -1;
				}
				num = search_tile((int)(terrains[i].tile_x - 1f), (int)(terrains[i].tile_z + 1f));
				if (num != -1)
				{
					terrains[i].neighbor.bottom_left = num;
				}
				else
				{
					terrains[i].neighbor.bottom_left = -1;
				}
				num = search_tile((int)(terrains[i].tile_x + 1f), (int)(terrains[i].tile_z - 1f));
				if (num != -1)
				{
					terrains[i].neighbor.top_right = num;
				}
				else
				{
					terrains[i].neighbor.top_right = -1;
				}
				num = search_tile((int)(terrains[i].tile_x - 1f), (int)(terrains[i].tile_z - 1f));
				if (num != -1)
				{
					terrains[i].neighbor.top_left = num;
				}
				else
				{
					terrains[i].neighbor.top_left = -1;
				}
				terrains[i].neighbor.self = i;
				terrains[i].index = i;
			}
		}
	}

	public void load_raw_heightmaps()
	{
		filter_class filter_class = null;
		ulong num = default(ulong);
		ulong num2 = default(ulong);
		for (int i = 0; i < prelayers.Count; i++)
		{
			for (int j = 0; j < prelayers[i].layer.Count; j++)
			{
				for (int k = 0; k < prelayers[i].layer[j].prefilter.filter_index.Count; k++)
				{
					filter_class = filter[prelayers[i].layer[j].prefilter.filter_index[k]];
					if (filter_class.type == condition_type_enum.RawHeightmap)
					{
						for (int l = 0; l < filter_class.raw.file_index.Count; l++)
						{
							if (filter_class.raw.file_index[l] > -1)
							{
								if (!raw_files[filter_class.raw.file_index[l]].loaded)
								{
									if (!raw_files[filter_class.raw.file_index[l]].exists())
									{
										if (script_base != null)
										{
											script_base.erase_raw_file(l);
										}
										erase_raw_file(l);
										filter_class.raw.file_index.RemoveAt(l);
										l--;
										if (filter_class.raw.file_index.Count == 0)
										{
											erase_filter(k, prelayers[i].layer[j].prefilter);
											k--;
										}
										continue;
									}
									raw_files[filter_class.raw.file_index[l]].bytes = File.ReadAllBytes(raw_files[filter_class.raw.file_index[l]].file);
									num = (uint)raw_files[filter_class.raw.file_index[l]].bytes.Length;
									num2 = (ulong)(raw_files[filter_class.raw.file_index[l]].resolution.x * raw_files[filter_class.raw.file_index[l]].resolution.y * 2f);
									if (num != num2)
									{
										UnityEngine.Debug.Log("Prelayer" + i + " -> Layer" + j + " -> Filter" + l + "\nThe Raw Heightmap file '" + raw_files[filter_class.raw.file_index[l]].file + "' has a lower resolution than selected. Please check the File size. It should be X*Y*2 = " + raw_files[filter_class.raw.file_index[l]].resolution.x + "*" + raw_files[filter_class.raw.file_index[l]].resolution.y + "*2 = " + raw_files[filter_class.raw.file_index[l]].resolution.x * raw_files[filter_class.raw.file_index[l]].resolution.y * 2f + " Bytes (" + raw_files[filter_class.raw.file_index[l]].resolution.x + "*" + raw_files[filter_class.raw.file_index[l]].resolution.y + " resolution). But the File size is " + raw_files[filter_class.raw.file_index[l]].bytes.Length + " Bytes (" + Mathf.Round(Mathf.Sqrt(raw_files[filter_class.raw.file_index[l]].bytes.Length / 2)) + "x" + Mathf.Round(Mathf.Sqrt(raw_files[filter_class.raw.file_index[l]].bytes.Length / 2)) + " resolution).");
										erase_raw_file(l);
										filter_class.raw.file_index.RemoveAt(l);
										l--;
										if (filter_class.raw.file_index.Count == 0)
										{
											erase_filter(k, prelayers[i].layer[j].prefilter);
											k--;
										}
										continue;
									}
									raw_files[filter_class.raw.file_index[l]].loaded = true;
								}
								if (i == 0 && !prelayers[0].prearea.active)
								{
									filter_class.raw.set_raw_auto_scale(terrains[0], terrains[0].prearea.area_old, raw_files, l);
								}
								else
								{
									filter_class.raw.set_raw_auto_scale(terrains[0], prelayers[i].prearea.area_old, raw_files, l);
								}
							}
							else
							{
								filter_class.raw.file_index.RemoveAt(l);
								l--;
								if (filter_class.raw.file_index.Count == 0)
								{
									erase_filter(k, prelayers[i].layer[j].prefilter);
									k--;
								}
							}
						}
					}
					load_raw_subfilter(filter_class, i, j);
				}
			}
		}
	}

	public void load_raw_subfilter(filter_class filter1, int count_prelayer1, int count_layer1)
	{
		subfilter_class subfilter_class = null;
		ulong num = default(ulong);
		ulong num2 = default(ulong);
		for (int i = 0; i < filter1.presubfilter.subfilter_index.Count; i++)
		{
			subfilter_class = subfilter[filter1.presubfilter.subfilter_index[i]];
			if (subfilter_class.type != condition_type_enum.RawHeightmap)
			{
				continue;
			}
			for (int j = 0; j < subfilter_class.raw.file_index.Count; j++)
			{
				if (subfilter_class.raw.file_index[j] > -1)
				{
					if (!raw_files[subfilter_class.raw.file_index[j]].loaded)
					{
						if (!raw_files[subfilter_class.raw.file_index[j]].exists())
						{
							script.erase_raw_file(j);
							erase_raw_file(j);
							subfilter_class.raw.file_index.RemoveAt(j);
							j--;
							if (subfilter_class.raw.file_index.Count == 0)
							{
								erase_subfilter(i, filter1.presubfilter);
								i--;
							}
							continue;
						}
						raw_files[subfilter_class.raw.file_index[j]].bytes = File.ReadAllBytes(raw_files[subfilter_class.raw.file_index[j]].file);
						num = (uint)raw_files[subfilter_class.raw.file_index[j]].bytes.Length;
						num2 = (ulong)(raw_files[subfilter_class.raw.file_index[j]].resolution.x * raw_files[subfilter_class.raw.file_index[j]].resolution.y * 2f);
						if (num != num2)
						{
							UnityEngine.Debug.Log("Prelayer" + count_prelayer1 + " -> Layer" + count_layer1 + " -> subfilter" + j + "\nThe Raw Heightmap file '" + raw_files[subfilter_class.raw.file_index[j]].file + "' has a lower resolution than selected. Please check the File size. It should be X*Y*2 = " + raw_files[subfilter_class.raw.file_index[j]].resolution.x + "*" + raw_files[subfilter_class.raw.file_index[j]].resolution.y + "*2 = " + raw_files[subfilter_class.raw.file_index[j]].resolution.x * raw_files[subfilter_class.raw.file_index[j]].resolution.y * 2f + " Bytes (" + raw_files[subfilter_class.raw.file_index[j]].resolution.x + "*" + raw_files[subfilter_class.raw.file_index[j]].resolution.y + " resolution). But the File size is " + raw_files[subfilter_class.raw.file_index[j]].bytes.Length + " Bytes (" + Mathf.Round(Mathf.Sqrt(raw_files[subfilter_class.raw.file_index[j]].bytes.Length / 2)) + "x" + Mathf.Round(Mathf.Sqrt(raw_files[subfilter_class.raw.file_index[j]].bytes.Length / 2)) + " resolution).");
							erase_raw_file(j);
							subfilter_class.raw.file_index.RemoveAt(j);
							j--;
							if (subfilter_class.raw.file_index.Count == 0)
							{
								erase_subfilter(i, filter1.presubfilter);
								i--;
							}
							continue;
						}
						raw_files[subfilter_class.raw.file_index[j]].loaded = true;
					}
					if (count_prelayer1 == 0 && !prelayers[0].prearea.active)
					{
						subfilter_class.raw.set_raw_auto_scale(terrains[0], terrains[0].prearea.area_old, raw_files, j);
					}
					else
					{
						subfilter_class.raw.set_raw_auto_scale(terrains[0], prelayers[count_prelayer1].prearea.area_old, raw_files, j);
					}
				}
				else
				{
					subfilter_class.raw.file_index.RemoveAt(j);
					j--;
					if (subfilter_class.raw.file_index.Count == 0)
					{
						erase_subfilter(i, filter1.presubfilter);
						i--;
					}
				}
			}
		}
	}

	public void Main()
	{
	}
}
